GIT Cheat Sheet - : by Ganesh Kumar
GIT Cheat Sheet - : by Ganesh Kumar
___
By Ganesh Kumar
What is Git ?
Git is the most commonly used Version Control System. Git tracks the changes you make to files, so you have a
record of what has been done, and you can revert to specific versions should you ever need to. Git also makes
the collaborations easier, allowing changes by multiple people to all be merge into one source.
SETUP:
GIT BASICS:
2 git clone [url] Retrieve an entire repository from a hosted location via URL
2 git add [file] Add a file as it looks now to your next commit (stage)
3 git reset [file] Unstage a file while retaining the changes in working
directory
5 git diff --staged Diff of what is staged but not yet committed
6 git commit -m “[descriptive message]” Commit your staged content as a new commit
snapshot
2
1 git branch List your branches. a * will appear next to the currently
active branch
3 git checkout Switch to another branch and check it out into your working
directory
4 git merge [branch] Merge the specified branch’s history into the current one
1 git log Show the commit history for the currently active branch
2 git log branchB..branchA Show the commits on branchA that are not on branchB
3 git log --follow [file] Show the commits that changed file, even across renames
5 git diff branchB...branchA Show the diff of what is in branchA that is not in branchB
2 git fetch [alias] Fetch down all the branches from that Git remote
3 git merge [alias]/[branch] Merge a remote branch into your current branch to bring it
up to date
4 git push [alias] [branch] Transmit local branch commits to the remote repository
branch
5 git pull Fetch and merge any commits from the tracking remote
branch
3
1 git rm [file] Delete the file from project and stage the removal for
commit
2 git mv [existing-path] [new-path] Change an existing file path and stage the move
3 git log --stat -M Show all commit logs with indication of any paths that
moved
REWRITE HISTORY
1 git rebase [branch] Apply any commits of current branch ahead of specified one
2 git reset --hard [commit] Clear staging area, rewrite working tree from specific
commit
TEMPORARY COMMITS
4 git stash drop Discard the changes from top of stash stack