Searchable reference of common Git commands for branching, undoing, stashing and more.
45 of 45 commands — click any row to copy
git init
Initialize a new Git repository in the current directory
git clone <url>
Clone a remote repository to your local machine
git config --global user.name "Name"
Set your global Git username
git config --global user.email "email"
Set your global Git email
git status
Show the working tree status — staged, unstaged and untracked files
git add <file>
Stage a file's changes for the next commit
git add .
Stage all changes in the current directory
git commit -m "message"
Commit staged changes with a message
git commit --amend
Modify the most recent commit (message and/or staged changes)
git diff
Show unstaged changes between working directory and index
git diff --staged
Show staged changes that will go into the next commit
git log
Show commit history for the current branch
git log --oneline --graph --all
Show a compact, graphical view of all branch history
git branch
List all local branches
git branch <name>
Create a new branch
git checkout <branch>
Switch to an existing branch
git checkout -b <branch>
Create a new branch and switch to it
git switch <branch>
Switch to an existing branch (modern alternative to checkout)
git switch -c <branch>
Create and switch to a new branch
git merge <branch>
Merge the specified branch into the current branch
git rebase <branch>
Reapply commits from the current branch on top of another branch
git branch -d <branch>
Delete a local branch (safe — only if merged)
git branch -D <branch>
Force-delete a local branch, even if unmerged
git remote -v
List configured remote repositories and their URLs
git remote add origin <url>
Add a new remote named 'origin'
git fetch
Download objects and refs from a remote without merging
git pull
Fetch and merge changes from the remote into the current branch
git push
Upload local commits to the remote branch
git push -u origin <branch>
Push a branch and set it as the upstream tracking branch
git push --force-with-lease
Force-push safely, aborting if the remote has new commits you don't have
git restore <file>
Discard local changes to a file (restore from index/HEAD)
git restore --staged <file>
Unstage a file without discarding its changes
git reset --soft HEAD~1
Undo the last commit but keep changes staged
git reset --hard HEAD~1
Undo the last commit and discard all its changes permanently
git revert <commit>
Create a new commit that undoes the changes from a previous commit
git clean -fd
Remove untracked files and directories from the working tree
git cherry-pick <commit>
Apply the changes from a specific commit onto the current branch
git stash
Temporarily save uncommitted changes and revert to a clean working tree
git stash pop
Re-apply the most recently stashed changes and remove them from the stash
git stash list
List all stashed changesets
git stash drop
Delete the most recent stash without applying it
git show <commit>
Show the metadata and changes introduced by a commit
git blame <file>
Show who last modified each line of a file and in which commit
git tag <name>
Create a tag pointing at the current commit
git describe --tags
Describe the current commit using the most recent reachable tag