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 developers 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).
git add -p <path>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 fetch --pruneIf I had to choose the git command which saved me the most time, I would probably go for this one. git reset --hard resets 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).
git reset --hard <remote> <branch>The --amend option of the commit command “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).
git commit --amendThis one is well-known, but I noticed some devs still don’t know about it yet, so, here we are 🙂: git cherry-pickapply the selected commit on top of the current head.
Full documentation here: Git — git-cherry-pick Documentation (git-scm.com).
git cherry-pick <commit># Show the last commit's diff
git show HEAD~
# Go back two commits behind the current head
git reset --hard HEAD~1
# And so on...
git cherry-pick HEAD~9Head~ 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!