Git Cheatsheet
A comprehensive guide to Git commands and best practices
Getting Started
git init
Initialize a new Git repository
git clone <url>
Clone a repository from remote URL
git config --global user.name "<name>"
Set your Git username
git config --global user.email "<email>"
Set your Git email
git config --list
List all Git configurations
Basic Commands
git status
Check repository status
git add <file>
Add file(s) to staging area
git add .
Add all modified files to staging area
git commit -m "<message>"
Commit staged changes with a message
git log
View commit history
git diff
Show changes between commits
Branching & Merging
git branch
List all branches
git branch <name>
Create a new branch
git checkout <branch>
Switch to specified branch
git checkout -b <name>
Create and switch to new branch
git merge <branch>
Merge specified branch into current branch
git branch -d <branch>
Delete a branch
Remote Operations
git remote -v
List all remote repositories
git remote add origin <url>
Add remote repository
git push origin <branch>
Push commits to remote repository
git pull origin <branch>
Pull changes from remote repository
git fetch
Download objects and refs from remote
git remote remove <name>
Remove a remote repository
Advanced Commands
git stash
Temporarily save uncommitted changes
git stash pop
Apply and remove stashed changes
git reset --hard <commit>
Reset to specific commit (discard changes)
git rebase <branch>
Reapply commits on top of another base
git cherry-pick <commit>
Apply specific commit to current branch
git tag <tagname>
Create a new tag at current commit
Inspection & Comparison
git log --oneline
View compressed log history
git blame <file>
Show who changed what and when in a file
git reflog
Show all ref updates in local repository
git show <commit>
Show various types of objects