This is our curated cheatsheet.
Sign In to create your own from your bookmarked commands.
Git Examples Cheatsheet
git add <pathname>
Stage changes for the next commit
git branch -v
List all branches including commit information
git checkout <branchname>
Switch to a different branch
git diff HEAD
Show uncommitted changes
git merge <branchname>
Merge a branch into the current branch
git restore --staged <pathname>
Unstages the specified file/s
git add <pathname>
Stage changes for the next commit
git branch -v
List all branches including commit information
git checkout <branchname>
Switch to a different branch
git diff HEAD
Show uncommitted changes
git merge <branchname>
Merge a branch into the current branch
git restore --staged <pathname>
Unstages the specified file/s
git branch -D <branchname>
Delete a branch forcefully
git branch -r
List remote branches
git checkout HEAD <filepath>
Restore a file from the most recent commit
git cherry-pick <commitA>
Apply the changes introduced by <commitA> on top of the current branch.
git clone <repo_url> <local_repo_name>
Creates a copy of a remote repository with a different name on your local machine
git commit --amend -m <message>
Change the commit message in the last commit
git diff HEAD --stat
View a summary of changes from the last commit
git log --oneline --graph
Displays condensed repository history in a graphical format.
git push origin -d <branchname>
Delete a remote branch
git show <commit>
Displays content changes of a specific commit
git stash save <message>
Stash changes with a custom message
git branch -D <branchname>
Delete a branch forcefully
git branch -r
List remote branches
git checkout HEAD <filepath>
Restore a file from the most recent commit
git cherry-pick <commitA>
Apply the changes introduced by <commitA> on top of the current branch.
git clone <repo_url> <local_repo_name>
Creates a copy of a remote repository with a different name on your local machine
git commit --amend -m <message>
Change the commit message in the last commit
git diff HEAD --stat
View a summary of changes from the last commit
git log --oneline --graph
Displays condensed repository history in a graphical format.
git push origin -d <branchname>
Delete a remote branch
git show <commit>
Displays content changes of a specific commit
git stash save <message>
Stash changes with a custom message
git branch -a --contains <commit>
List all branches that contain commit <commit>, including remote branches.
git checkout --theirs <path>
Resolve a merge conflict by accepting the "incoming" branch changes
git config --global user.name <username>
Set the global username for git
git grep -i "search pattern"
Search for patterns in the repository, ignoring the case of the search pattern
git push -u <remote> <branchname>
Push commits to a remote repository
git rebase -i HEAD~<number>
Interactively rebase the last <number> commits.
git reset --hard
Discard all changes and revert to the commit specified
git stash -u
Stash all changes including untracked files
git stash apply stash@{<number>}
Apply a specific stash to the working directory
git branch -a --contains <commit>
List all branches that contain commit <commit>, including remote branches.
git checkout --theirs <path>
Resolve a merge conflict by accepting the "incoming" branch changes
git config --global user.name <username>
Set the global username for git
git grep -i "search pattern"
Search for patterns in the repository, ignoring the case of the search pattern
git push -u <remote> <branchname>
Push commits to a remote repository
git rebase -i HEAD~<number>
Interactively rebase the last <number> commits.
git reset --hard
Discard all changes and revert to the commit specified
git stash -u
Stash all changes including untracked files
git stash apply stash@{<number>}
Apply a specific stash to the working directory