Git Cheat Sheet
Comprehensive Git workflow reference guide
Git Cheat Sheet
Comprehensive reference guide for Git workflows and commands. Click the copy button to copy any command.
123
Total Commands
123
Filtered Results
Setup and Configuration
Command | Copy | Description |
---|---|---|
git config --global user.name "Your Name" | Set your name | |
git config --global user.email "email@example.com" | Set your email | |
git config --global color.ui true | Enable colorization | |
git config --global core.editor "vim" | Set default editor | |
git config --list | List all configuration | |
git config --global alias.co checkout | Create alias for checkout | |
git config --global alias.br branch | Create alias for branch | |
git config --global alias.st status | Create alias for status |
Creating Repositories
Command | Copy | Description |
---|---|---|
git init | Initialize new repository | |
git init <directory> | Initialize repository in directory | |
git clone <url> | Clone repository | |
git clone <url> <directory> | Clone to specific directory | |
git clone --depth 1 <url> | Shallow clone (latest commit only) |
Basic Workflow
Command | Copy | Description |
---|---|---|
git status | Check status of files | |
git status -s | Short status | |
git add <file> | Stage specific file | |
git add . | Stage all changes | |
git add -A | Stage all (including deletions) | |
git add -p | Interactive staging | |
git diff | Show unstaged changes | |
git diff --staged | Show staged changes | |
git diff HEAD | Show all changes | |
git commit -m "message" | Commit with message | |
git commit -am "message" | Stage and commit all | |
git commit --amend | Amend last commit | |
git commit --amend --no-edit | Amend without changing message |
Branching
Command | Copy | Description |
---|---|---|
git branch | List all local branches | |
git branch -a | List all branches (local and remote) | |
git branch -r | List remote branches | |
git branch <name> | Create new branch | |
git branch -d <name> | Delete branch | |
git branch -D <name> | Force delete branch | |
git branch -m <old> <new> | Rename branch | |
git checkout <branch> | Switch to branch | |
git checkout -b <branch> | Create and switch to branch | |
git checkout - | Switch to previous branch | |
git switch <branch> | Switch branches (modern) | |
git switch -c <branch> | Create and switch (modern) |
Merging
Command | Copy | Description |
---|---|---|
git merge <branch> | Merge branch into current | |
git merge --no-ff <branch> | Merge with merge commit | |
git merge --squash <branch> | Squash and merge | |
git merge --abort | Abort merge | |
git mergetool | Open merge tool |
Remote Repositories
Command | Copy | Description |
---|---|---|
git remote | List remotes | |
git remote -v | List remotes with URLs | |
git remote add <name> <url> | Add remote | |
git remote remove <name> | Remove remote | |
git remote rename <old> <new> | Rename remote | |
git remote show <name> | Show remote info | |
git fetch | Fetch from all remotes | |
git fetch <remote> | Fetch from specific remote | |
git fetch --prune | Fetch and remove deleted branches | |
git pull | Fetch and merge | |
git pull --rebase | Fetch and rebase | |
git push | Push to remote | |
git push <remote> <branch> | Push branch to remote | |
git push -u origin <branch> | Push and set upstream | |
git push --all | Push all branches | |
git push --tags | Push all tags | |
git push --force | Force push (dangerous) | |
git push --force-with-lease | Safer force push |
History and Logs
Command | Copy | Description |
---|---|---|
git log | Show commit history | |
git log --oneline | Condensed history | |
git log --graph | Show graph | |
git log --graph --oneline --all | Visual branch history | |
git log -n 5 | Show last 5 commits | |
git log --author="name" | Filter by author | |
git log --since="2 weeks ago" | Filter by date | |
git log --follow <file> | Show file history | |
git log -p | Show changes in commits | |
git show <commit> | Show commit details | |
git show <commit>:<file> | Show file at commit | |
git blame <file> | Show who changed each line |
Undoing Changes
Command | Copy | Description |
---|---|---|
git checkout -- <file> | Discard changes in file | |
git restore <file> | Restore file (modern) | |
git restore --staged <file> | Unstage file | |
git reset <file> | Unstage file | |
git reset --soft HEAD~1 | Undo commit, keep changes staged | |
git reset HEAD~1 | Undo commit, keep changes unstaged | |
git reset --hard HEAD~1 | Undo commit, discard changes | |
git reset --hard origin/main | Reset to remote state | |
git revert <commit> | Create new commit to undo | |
git revert HEAD | Revert last commit | |
git clean -fd | Remove untracked files/directories | |
git clean -fdn | Dry run of clean |
Stashing
Command | Copy | Description |
---|---|---|
git stash | Stash changes | |
git stash save "message" | Stash with message | |
git stash -u | Stash including untracked | |
git stash list | List stashes | |
git stash show | Show latest stash | |
git stash show -p | Show stash diff | |
git stash pop | Apply and remove stash | |
git stash apply | Apply stash | |
git stash apply stash@{2} | Apply specific stash | |
git stash drop | Delete stash | |
git stash clear | Delete all stashes | |
git stash branch <branch> | Create branch from stash |
Tagging
Command | Copy | Description |
---|---|---|
git tag | List tags | |
git tag <name> | Create lightweight tag | |
git tag -a <name> -m "message" | Create annotated tag | |
git tag <name> <commit> | Tag specific commit | |
git tag -d <name> | Delete local tag | |
git push origin <tag> | Push tag | |
git push origin --tags | Push all tags | |
git push origin :refs/tags/<tag> | Delete remote tag |
Rebasing
Command | Copy | Description |
---|---|---|
git rebase <branch> | Rebase onto branch | |
git rebase -i HEAD~3 | Interactive rebase last 3 commits | |
git rebase --continue | Continue after resolving conflicts | |
git rebase --skip | Skip current commit | |
git rebase --abort | Abort rebase | |
git rebase origin/main | Rebase on remote main |
Cherry-picking
Command | Copy | Description |
---|---|---|
git cherry-pick <commit> | Apply commit to current branch | |
git cherry-pick <commit1> <commit2> | Cherry-pick multiple commits | |
git cherry-pick --continue | Continue cherry-pick | |
git cherry-pick --abort | Abort cherry-pick |
Advanced
Command | Copy | Description |
---|---|---|
git reflog | Show reference logs | |
git bisect start | Start binary search | |
git bisect good | Mark commit as good | |
git bisect bad | Mark commit as bad | |
git bisect reset | End bisect session | |
git worktree add <path> <branch> | Create linked working tree | |
git worktree list | List working trees | |
git worktree remove <path> | Remove working tree |
All operations are performed locally in your browser. No data is sent to any server.
About Git Cheat Sheet
This section will contain detailed, SEO-friendly content about the Git Cheat Sheet.
In the future, this content will be managed through a headless CMS, allowing you to:
- Add detailed explanations about how to use this tool
- Include examples and use cases
- Provide tips and best practices
- Add FAQs and troubleshooting guides
- Update content without touching the code
How to Use
Step-by-step instructions for using the Git Cheat Sheet will appear here. This content will be fully customizable through the admin panel.
Features
Key features and benefits of this tool will be listed here. All content is editable via the CMS.