This cheat sheet features the most important and commonly used Git commands for easy reference.
Configuring user information used across all local repositories
git config --global user.name "[UserName]"
git config --global user.email "[valid-email]"
git config --global color.ui auto
Removes user information configuration across all local repositories
git config --global --unset user.name
git config --global --unset user.email
Configuring user information, initializing and cloning repositories
git init
git clone [url]
Working with snapshots and the Git staging area
Shows modified files in working directory, staged for your next commit
git status
It adds changes to staging area. This command stages the changes made to files and prepares them for the next commit.
git add [fileName]
git add .
git add -A
It resets changes in the working directory.
git reset [file]
git reset --hard HEAD
It shows changes between commits, commit and working tree, etc. It also compares the branches.
git diff
git diff HEAD-1 HEAD
git diff [branch-1] [branch-2]
git diff --staged
Isolating work in branches, changing context, and integrating changes
It lists, creates or deleyes branches in a repository. To delete the branch using git checkout and then run command to delete the branch locally
git branch
git branch [branch-name]
git branch -d [branch-name]
Switch to another branch and check it out into your working directory
git checkout [branch-name]
Merge the specified branch’s history into the current one
git merge [branch]
Examining logs, diffs and object information
git log
git log [branchB]..[branchA]
git log --follow [file]
git diff [branchB]...[branchA]
git show [SHA]
Retrieving updates from another repository and updating local repos
git remote add [alias] [url]
git fetch [alias]
git merge [alias]/[branch]
git push [alias] [branch]
git pull
Versioning file removes and path changes
git rm [file]
git mv [existing-path] [new-path]
git log --stat -M
Rewriting branches, updating commits and clearing history
git rebase [branch]
git reset --hard [commit]
Temporarily store modified, tracked files in order to change branches
git stash
git stash list
git stash pop
git stash drop
Preventing unintentional staging or commiting of files
logs/
*.notes
pattern*/
git config --global core.excludesfile [file]