Git and Github Commands 1719287860
Git and Github Commands 1719287860
Git – It’s a version control system which is used to track the back history of the code and collaborate
with other developers adding code within git.
Github – Git is a tool or software that runs on our computer system but this Github is a website that
allows various developers to store and manage code using git.
In Github the repository is folders where we as developers store and manage our codes.
(github.com).
Repositories – These are the folders where we upload our whole project files.
These repos could be either public or private depending upon visibility of files or other content.
➔ Git – VS Code – Windows Git Bash – Mac (Terminal) with git –version.
➔ Git Commands –
1) Clone – Cloning a repository on our local machine – Making duplicate clone copy of github
repo on our laptop.
Git status
Global – github
Local – laptop/pc
Untracked
Modified
Staged
Unmodified
➔ Git Push Commands – It uploads the local repo content to remote repo and git pushes it to
origin main.
➔ Git add and commit commands.
➔ Basic git commands – git add . , git status , git commit -m "Add the initial files"
➔ Git init commands->
Git init
Git remote add origin <link>
Git remote -v (to verify remote)
Git branch (to check branch)
Git branch -M main (to rename branch)
Git push origin main
➔ Git branch commands
Git branch
Git branch -M main
Git checkout <branch-name> (to navigate branches)
Git checkout -b <new-branch-name> (to create new branch)
git branch -d branch-name→ (to delete the branch)
➔ PR – Pull Request – It lets you tell others about changes you’ve pushed in a repo on GitHub.
➔ Fork - It’s a new repo that shares code and visibility settings with the original “upstream”.
➔ Fork is a rough copy.
GIT CHEAT SHEET
Git is the free and open source distributed version control system that's responsible for everything GitHub
related that happens locally on your computer. This cheat sheet features the most important and commonly
used Git commands for easy reference.
Git for All Platforms diff of what is changed but not staged
http://git-scm.com
git diff --staged
set a name that is identifiable for credit when review version history
git config --global user.email “[valid-email]”
BRANCH & MERGE
Isolating work in branches, changing context, and integrating changes
set an email address that will be associated with each history marker
git branch
git config --global color.ui auto
list your branches. a * will appear next to the currently active branch
set automatic command line coloring for Git for easy reviewing
git branch [branch-name]
initialize an existing directory as a Git repository merge the specified branch’s history into the current one
git clone [url] git log
retrieve an entire repository from a hosted location via URL show all commits in the current branch’s history
INSPECT & COMPARE SHARE & UPDATE
Examining logs, diffs and object information Retrieving updates from another repository and updating local repos
show the commit history for the currently active branch add a git URL as an alias
git log branchB..branchA git fetch [alias]
show the commits on branchA that are not on branchB fetch down all the branches from that Git remote
git log --follow [file] git merge [alias]/[branch]
show the commits that changed file, even across renames merge a remote branch into your current branch to bring it up to date
git diff branchB...branchA git push [alias] [branch]
show the diff of what is in branchA that is not in branchB Transmit local branch commits to the remote repository branch
git show [SHA] git pull
show any object in Git in human-readable format fetch and merge any commits from the tracking remote branch
delete the file from project and stage the removal for commit apply any commits of current branch ahead of specified one
change an existing file path and stage the move clear staging area, rewrite working tree from specified commit
show all commit logs with indication of any paths that moved TEMPORARY COMMITS
Temporarily store modified, tracked files in order to change branches
system wide ignore pattern for all local repositories discard the changes from top of stash stack
Education
Teach and learn better, together. GitHub is free for students and teach- [email protected]
ers. Discounts available for other educational uses. education.github.com