Git can do much more than add, commit, push. Here are 15 commands that will take you from user to power user.
1. git stash¶
git stash push -m “WIP: login form” git stash list git stash pop git stash apply stash@{2}
2. git log –oneline –graph¶
git log –oneline –graph –all –decorate
3. git bisect — Binary Bug Search¶
git bisect start git bisect bad git bisect good v1.0.0
15 Git Commands Every Developer Should Know¶
git bisect reset
4. git rebase -i¶
git rebase -i HEAD~5
pick, squash, reword, edit, drop, fixup¶
5. git cherry-pick¶
git cherry-pick abc1234
6. git reflog — Safety Net¶
git reflog git checkout HEAD@{5}
7. git blame¶
git blame -L 10,20 src/app.py git blame -w # ignores whitespace
8. git diff –staged¶
git diff –staged git diff –stat
9. git commit –amend¶
git commit –amend -m “better description” git commit –amend –no-edit
10. git clean¶
git clean -fd git clean -fdn # dry run
11. git worktree¶
git worktree add ../hotfix hotfix-branch
12. git shortlog¶
git shortlog -sn –since=”1 month ago”
13. git tag¶
git tag -a v1.0.0 -m “Release 1.0” git push origin –tags
14. git reset¶
git reset –soft HEAD~1 # keeps changes staged git reset –mixed HEAD~1 # changes unstaged git reset –hard HEAD~1 # deletes everything
15. Aliases¶
git config –global alias.co checkout git config –global alias.st status git config –global alias.undo “reset HEAD~1 –mixed”
Conclusion¶
These commands cover 95% of situations. Learn them one by one — in a month you’ll be a Git ninja.