Skip to content
ShapppesLog inSign up

Shapppes - Create, share, and discover stories

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

Discover 6 essential Git commands that can boost your productivity and streamline your workflow. Perfect for beginners looking to master this powerful tool!

Développeur FullStack Laravel / Vue-React - UX – UI Designer | Createur de Shapppes.com

1 min read

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 --prune

If 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 --amend

This 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~9

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!

Topics

Written by

Gaël Duval

Développeur FullStack Laravel / Vue-React - UX – UI Designer | Createur de Shapppes.com

Créateur de Shapppes. Plus de 7 ans sur Laravel, 3 ans avec Vue.js et React. Full-stack qui conçoit et façonne l’UI/UX, clarifie les besoins avec les clients et livre des produits nets et vivants.

More from Gaël Duval

Discussion

Be the first to comment.

Log in to join the discussion.