A Summary of Git Commands I Frequently Use at Work
I've put together the ones I kept looking up again, especially when I was a new hire. Everyone knows the basic commands, so I focused on the slightly less common ones.
1. git switch - : switch straight back to the previous branch
2. git restore --staged <file> : undo only the add/staging, keep the file changes
3. git log --oneline --graph -20 : view history at a glance
4. git stash push -m "message" : stash with a message attached
5. git diff --stat : summarize which files changed and by how much
6. git commit --amend : edit the last commit message/content (only before pushing)
7. git reset --soft HEAD~1 : undo only the commit and leave the changes staged
I especially use #7 often when splitting commits. If it seems like I should commit but something feels ambiguous, I commit first and then roll it back with --soft to reorganize.
When it looks like there might be a conflict, also remember git merge --abort. There was a time I didn't know this and just closed the terminal window.
4 answers
Number 7, --soft, is a total game changer lol. There’s nothing more convenient when cleaning up commits into logical units. It’s especially useful for splitting up a big clump of commits before opening a PR.
Well, isn't git switch - ultimately the same as checkout -? For people already used to it, I wonder if there's any reason to learn something new.
I'm one of those people who always slaps on --abort because I'm scared of conflicts... It would've been nice if you'd covered reflog as part of the set too—what a shame. But the summary is clean, I admit.
I just learned about git diff --stat. Until now I only used --name-only. But I get confused about how restore --staged differs from reset HEAD, so I still use reset lol