Git Commands Cheatsheet
Searchable reference of essential Git commands with examples
gitcommandscheatsheetreferenceversion control
Showing 57 of 57 commands
| Category | Command | Description | |
|---|---|---|---|
| Setup | git init | Initialize a new Git repository | |
| Setup | git clone <url> | Clone a remote repository | |
| Setup | git config --global user.name "Name" | Set global username | |
| Setup | git config --global user.email "email" | Set global email | |
| Basic | git status | Show working tree status | |
| Basic | git add . | Stage all changes | |
| Basic | git add <file> | Stage a specific file | |
| Basic | git commit -m "message" | Commit staged changes with a message | |
| Basic | git commit --amend | Modify the last commit | |
| Basic | git log | Show commit history | |
| Basic | git log --oneline | Show compact commit history | |
| Basic | git log --graph --all | Show branch graph | |
| Basic | git diff | Show unstaged changes | |
| Basic | git diff --staged | Show staged changes | |
| Basic | git show <commit> | Show a specific commit | |
| Branching | git branch | List local branches | |
| Branching | git branch <name> | Create a new branch | |
| Branching | git branch -d <name> | Delete a branch | |
| Branching | git branch -D <name> | Force delete a branch | |
| Branching | git checkout <branch> | Switch to a branch | |
| Branching | git checkout -b <branch> | Create and switch to a new branch | |
| Branching | git switch <branch> | Switch branches (modern) | |
| Branching | git switch -c <branch> | Create and switch branches (modern) | |
| Branching | git merge <branch> | Merge a branch into current | |
| Branching | git rebase <branch> | Rebase current branch onto another | |
| Branching | git rebase -i HEAD~3 | Interactive rebase last 3 commits | |
| Branching | git cherry-pick <commit> | Apply a specific commit | |
| Remote | git remote -v | Show remote connections | |
| Remote | git remote add origin <url> | Add a remote | |
| Remote | git fetch origin | Fetch from remote without merging | |
| Remote | git pull origin <branch> | Fetch and merge from remote | |
| Remote | git push origin <branch> | Push branch to remote | |
| Remote | git push --force-with-lease | Safe force push | |
| Remote | git push origin --delete <branch> | Delete remote branch | |
| Remote | git push --tags | Push all tags to remote | |
| Stash | git stash | Stash current changes | |
| Stash | git stash push -m "message" | Stash with a message | |
| Stash | git stash list | List all stashes | |
| Stash | git stash pop | Apply and remove last stash | |
| Stash | git stash apply stash@{0} | Apply a specific stash | |
| Stash | git stash drop stash@{0} | Delete a specific stash | |
| Undo | git reset HEAD <file> | Unstage a file | |
| Undo | git reset --soft HEAD~1 | Undo last commit, keep changes staged | |
| Undo | git reset --mixed HEAD~1 | Undo last commit, keep changes unstaged | |
| Undo | git reset --hard HEAD~1 | Undo last commit and discard changes | |
| Undo | git revert <commit> | Create a new commit undoing a commit | |
| Undo | git checkout -- <file> | Discard changes in a file | |
| Undo | git restore <file> | Restore file (modern) | |
| Tags | git tag | List all tags | |
| Tags | git tag v1.0.0 | Create a lightweight tag | |
| Tags | git tag -a v1.0.0 -m "Release" | Create an annotated tag | |
| Tags | git push origin v1.0.0 | Push a tag to remote | |
| Advanced | git bisect start | Start binary search for bug | |
| Advanced | git blame <file> | Show who changed each line | |
| Advanced | git reflog | Show history of HEAD movements | |
| Advanced | git submodule add <url> | Add a submodule | |
| Advanced | git worktree add <path> | Add a linked working tree |