Git Cheats¶
A categorized compendium of the most useful, commonly referenced git commands, workflows, and tips for daily use and troubleshooting.
Hand-crafted with ❤️ for rapid reference.
Not intended as a replacement for the official documentation
Quick Command Reference¶
Setup & Configuration¶
Check Git Version¶
Verify your Git installation
Set Identity¶
Configure your name for commits
Configure your email for commits
git config --global user.email "[email protected]"
Editor Configuration¶
Set VS Code as default editor
Set Vim as default editor
Set Notepad++ as default editor
git config --global core.editor "'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"
Set Sublime Text as default editor
View Configuration¶
Display all configurations
View a specific config value
Configuration Scopes¶
System-wide configuration (all users)
User configuration (current user)
Repository configuration (current repo only)
Repository Operations¶
Create New Repository¶
Initialize a new Git repository in current directory
Clone Existing Repository¶
Clone via HTTPS
Clone via SSH
git clone [email protected]:username/repository.git
Clone to specific directory
Clone specific branch
Clone with limited history (shallow clone)
Ignore Files¶
Create gitignore file to specify ignored files
Basic Workflow¶
Check Status¶
View repository status
View condensed status output
Stage Changes¶
Stage a specific file
Stage all changes
Stage all changes (including deleted files)
Stage changes interactively
Commit Changes¶
Commit with a message
Add tracked files and commit in one step
Amend the previous commit
View Changes¶
Show unstaged changes
Show staged changes
Show changes by filename only
Undo Changes¶
Restore file from HEAD
Unstage changes (keep in working directory)
Restore file from a specific commit
File Operations¶
Remove files from Git and filesystem
Remove files from Git but keep in filesystem
Remove directory recursively
Move or rename files
Branching & Merging¶
Branch Management¶
Create a new branch
Create and switch to new branch
Alternative to create and switch to new branch (Git 2.23+)
List local branches
List all branches (local and remote)
Switch to an existing branch
Alternative to switch branches (Git 2.23+)
Delete a branch (safe, prevents deletion of unmerged branches)
Force delete a branch
Rename current branch
Rename specific branch
Push and track branch
Compare branches
Merging¶
Merge a branch into current branch
Merge with no fast-forward (always creates merge commit)
Merge and squash commits into a single one
Abort an in-progress merge
Rebasing¶
Rebase current branch onto another
Interactive rebase for editing commits
Continue rebase after resolving conflicts
Cherry-picking¶
Apply a specific commit to current branch
Handle Conflicts¶
Get a specific file from another branch
List conflicting files
Remote Operations¶
Remote Management¶
Add a remote repository
List all remotes with URLs
Sync with Remotes¶
Download remote data without merging
Download and merge from remote
Download and rebase instead of merging
Upload local commits to remote
Push and set up tracking
Delete a remote branch
List remote branches
Stash & Clean¶
Stash Management¶
Save working changes temporarily
List all stashes
Show stash details
Apply stash without removing it
Apply and remove stash
Remove a stash
Remove all stashes
Stash specific files only
Stash with a descriptive message
Working Directory Cleanup¶
Preview what would be removed
Remove untracked files
Remove untracked files and directories
History & Inspection¶
View History¶
Show commit history
Show compact history
Show history with branch graph
Show history for a specific file
Show history with changes
Inspect Changes¶
See who changed each line in a file
Show changes between working directory and HEAD
Show changes between staged and HEAD
Compare two commits
Compare two branches
Show details of a specific commit
Search for specific content in history
Tags & Releases¶
Tag Management¶
Create a lightweight tag
Create an annotated tag
List all tags
Show tag details
Push specific tag to remote
Push all tags to remote
Delete a local tag
Delete a remote tag
Checkout a tagged version
Create a tag for a previous commit
Troubleshooting¶
Fix Mistakes¶
Modify the last commit
Undo last commit but keep changes staged
Undo last commit and unstage changes
Discard all local changes
View reference history log
Recover deleted work from reflog
Cancel current merge operation
Create branch when in detached HEAD state
Force push with safety mechanism
Optimize repository
Advanced Usage¶
Git Hooks¶
Path to pre-commit hook
Object Inspection¶
Examine Git objects
External Repositories¶
Add a submodule
Add a subtree
Debugging¶
Find the commit that introduced a bug
git bisect start
git bisect bad # Mark current commit as bad
git bisect good v1.0 # Mark a known good commit
History Rewriting¶
Interactive history editing
Rewrite complete history
Patch Management¶
Create a patch file
Apply a patch file
Repository Management¶
Create a portable repository bundle
Search code in repository
Create additional working directory
Partial repository checkout
Development Workflows¶
Feature Development¶
Start a new feature branch
Push new feature branch to remote
Working with Forks¶
Add original repository as upstream
Sync fork with original repository
GitFlow Operations¶
Start a new feature using GitFlow
Finish a feature using GitFlow
Start a new release using GitFlow
Finish a release using GitFlow
Create a hotfix using GitFlow
Exploring Git Topics¶
Git Fundamentals
Branch Management
Remote Collaboration
- Working with remote repositories (push, pull, fetch)
- Temporarily storing changes and cleaning working directory
Project History & Versions
Customization & Troubleshooting
Advanced Usage