A Brief Overview of Git (Not Really)
Git is a distributed version control system that helps developers track changes, collaborate seamlessly, and avoid catastrophic mistakes (most of the time). It lets you experiment with code, roll back when things go south, and work with teams without stepping on each other’s toes.
But let’s be real—you probably already know that. If you’re here, you’re likely using Git daily. Over the years, I’ve picked up a few commands that have saved me from disaster (and awkward conversations with my manager). Here are 5 that might do the same for you.
Git Cherry-pick <commit-hash>
Ever committed the perfect fix but realised too late that you were on the wrong branch? Instead of manually copying and pasting changes, git cherry-pick
lets you grab specific commits from one branch and apply them to another. A lifesaver when you don’t want to redo work.
The best part about this is only the changes committed to the git are copied, so if you have a completely different environment, you do not have to worry about changes from wrong A going to wrong B when you cherry-pick
Git stash and Git stash apply
Has this ever happened to you?
You’re deep into a feature, feeling like a 10x engineer, only to realise you’ve been working on the wrong branch. Panic mode? Nope—just usegit stash
git stash
temporarily removes all uncommitted changes, cleaning up your working directory.Switch to the correct branch.
Run
git stash apply
and voilà—your changes are applied to the right branch.
Git makes this work by saving your uncommitted changes into a hidden stack within Git's internal storage. When you run git stash apply
, Git retrieves the latest stash entry and reapplies the saved changes to your working directory—without affecting the commit history.
Git merge
Merging is standard practice you’re probably familiar with. However, there are some other options than you might be used to for your consideration:
Fast-forward merge (
git merge <branch>
)- If the target branch has no new commits, Git simply moves the pointer forward. No merge commit is created.
No fast-forward merge (
git merge --no-ff <branch>
)- Forces a merge commit even if a fast-forward is possible, keeping a clear history of branch merges.
Squash merge (
git merge --squash <branch>
)- Combines all commits from the branch into a single commit before merging, keeping the history cleaner.
Recursive merge (
git merge -s recursive <branch>
)- Default strategy for merging two branches with a shared history, automatically handling simple conflicts.
I personally use git merge --no-ff <branch>
because I prefer to preserve the branch history and make it easier to track when and why a feature was merged. This helps maintain a structured Git log, especially in team environments.
Git reset and Git revert
Ever pushed code and immediately regretted it? Of course, you have. But do you reset or revert?
git reset
rewinds history, making it seem like the bad commit never happened (great locally, dangerous if already pushed).git revert
creates a new commit that undoes the changes while keeping the commit history intact.
If you need to backtrack safely in a shared repo, git revert
is your friend.
Git commit (Yes really)
I know what you’re thinking—why is git commit even on this list? Well, let’s be honest: if I didn’t commit, how would I prove I actually wrote that feature?
Also, I stick to a single-commit principle—bundling related changes into a single, well-documented commit. Some engineers like making a ton of changes before committing, but that just makes debugging a nightmare.
Final Thoughts
Git is powerful, but there are a few extra commands that can make life so much easier. These six have saved me countless times—and maybe they’ll save you too. Got any Git tricks that help you keep your job? Drop them in the comments. 🚀