6 Git commands and tips I use daily that can improve your productivity.

Git is one of the tools I can’t imagine going without for any of my projects, and I know it is also true for almost all developers as well.
However, I recently noticed that a lot of devs are quite inexperienced with it and only stick with the basics: git add
, git commit
, git push
and git merge
, although git is an incredibly powerful and complex tool that does way more than this.
Here are 6 commands and tips (for beginners) that I use daily, that improve my productivity a lot.

Using the -p
flag on the git add
command lets you choose chunks of code you want to stage. It’s super useful to quickly review your code before committing and avoid pushing debug statements, commented code, or anything you could have forgotten. Give it a try!
Full documentation here: Git — git-add Documentation (git-scm.com).

The --prune
(or -p
) option will “remove any remote-tracking references that no longer exist on the remote”.
Full documentation here: Git — git-fetch Documentation (git-scm.com).

git reset --hard
reset your current branch’s working tree to the working tree to match.If I had to choose the git command which saved me the most time, I would probably go for this one. git reset --hard
reset your current branch’s working tree to the working tree to match. Keep this one in mind, it will save you a ton of time someday 🙂.
Full documentation here: Git — git-reset Documentation (git-scm.com).

The --amend
option “Replace the tip of the current branch by creating a new commit”, quite handy when you notice a mistake in the name of the commit or when some changes have been forgotten.
Full documentation here: Git — git-commit Documentation (git-scm.com).

This one is well-known, but I noticed some devs still don’t know about it yet, so, here we are 🙂: git cherry-pick
apply the selected commit on top of the current head.
Full documentation here: Git — git-cherry-pick Documentation (git-scm.com).

Head~
lets you target previous commits without having to look for its hash 👍. Again, pretty handy and a great time saver!
Hope you find this article useful! Let me know what command you use, or if there are any better ways to go!