This guide is for developers who already know the basics and want to level up their Git game.
1. Rebasing Instead of Merging
Rebasing rewrites commit history to make it cleaner:
git checkout feature
git rebase main
- Reapplies your feature branch commits on top of
main - Keeps history linear and easier to read
- ⚠️ Avoid rebasing shared branches
Interactive rebase:
git rebase -i HEAD~5
- Edit, squash, or reorder last 5 commits
2. Stashing Changes
Temporarily save unfinished work:
git stash
Apply stashed changes later:
git stash apply
List stashes:
git stash list
Pop stash (apply + remove from stash list):
git stash pop
3. Cherry-Picking Commits
Apply a specific commit from another branch:
git checkout main
git cherry-pick <commit-hash>
Useful for hotfixes or bringing isolated features across branches.
4. Undoing Commits Safely
Reset vs Revert:
- Reset – rewrites history:
git reset --hard HEAD~1
- Revert – creates a new commit to undo changes:
git revert <commit-hash>
Use revert on public branches, reset for local experiments.
5. Advanced Log & History Tools
- Show compact commit history with branches:
git log --oneline --graph --decorate --all
- Check changes between commits:
git diff <commit1> <commit2>
- Check changes staged for commit:
git diff --staged
6. Git Tags
Mark releases or milestones:
git tag v1.0
git push origin v1.0
List tags:
git tag
7. Remote Branch Management
Delete a remote branch:
git push origin --delete feature-branch
Prune obsolete remote branches:
git fetch -p
8. Aliases for Speed
Save time with shortcuts:
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.st status
Now git co feature is the same as git checkout feature.
Git Visual Cheat Sheet
Here’s a quick visual reference for commands:
# Create & Clone Repos
git init # Initialize repo
git clone <url> # Clone repo
# Staging & Committing
git add <file> # Stage file
git add . # Stage all files
git commit -m "msg" # Commit changes
# Branching & Merging
git branch # List branches
git checkout <branch> # Switch branch
git checkout -b <branch> # Create + switch
git merge <branch> # Merge branch
git rebase <branch> # Rebase branch
# Syncing Remotes
git fetch # Fetch remote changes
git pull # Pull + merge remote changes
git push # Push local changes
# Undo Changes
git reset <file> # Unstage file
git checkout -- <file> # Discard changes
git revert <commit> # Undo commit safely
git reset --hard <commit># Reset history
# Stash & Cherry-Pick
git stash # Save unfinished work
git stash pop # Apply stash
git cherry-pick <commit> # Apply specific commit
# Logs & Tags
git log --oneline --graph # Visual log
git tag v1.0 # Tag a release
# Remote Cleanup
git push origin --delete <branch> # Delete remote branch
git fetch -p # Prune deleted remote branches

