15 Git Tips You Should Know
Fifteen Git commands that go past add, commit, and push: undoing a commit without losing work, partial stashes, interactive rebase, reflog branch recovery, git bisect, empty commits to poke CI, and aliases to save your fingers.
Most of us use maybe six Git commands day to day and never touch the rest. This is a list of fifteen that are worth actually committing to memory, because each one saves you from either losing work or doing something tedious by hand. Nothing exotic, just the stuff that pays off once you know it's there.
A few of the highlights: git reset --soft HEAD~1 undoes your last commit but keeps the changes staged. git stash push -m "msg" file1 file2 stashes only the files you name instead of everything. git reflog plus git checkout -b brings back a branch you deleted by accident. git bisect start/bad/good binary-searches your history to find the commit that introduced a bug. git commit --allow-empty -m "msg" makes a commit with no changes, which is handy for kicking off a CI run. And git config --global alias.co checkout (and friends) lets you stop typing the long versions.
Key takeaways
- Undo options differ:
git reset --softkeeps changes staged,git commit --amendrewrites the last commit, older needsgit rebase -i HEAD~n git reflogis the safety net: if you committed at all, that state is almost always recoverable even with the branch gone- Small wins add up:
git checkout -to bounce between branches,git log --oneline --graph --decorate --allfor readable history,git pull --rebaseto skip merge commits
Who this is for
Developers who are comfortable with the basics and want to get more out of Git without reading the whole man page. Every tip is a single command with a one-line explanation, so it works fine as a reference you skim and come back to.
The full list, with all fifteen commands and what each one does, is on DEV.to.