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

Git.
Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.

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.

The git command: git add -p
-p option lets you choose chunks of code you want to stage.

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 git command: git fetch — prune
— prune flag remove any remote-tracking references that no longer exist on the remote.

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).

The git command: git reset — hard command
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 git command: git ci — amend
Replace the tip of the current branch by creating a new commit.

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).

The git command: git cherry-pick
Apply the selected commit on top of the current head.

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).

Head~ lets you target previous commits
Target previous commits.

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!

--

--

--

Hey 👋 I'm Gaël Duval, freelance Fullstack Developer and UI - UX Designer from France (Paris) ! https://duvalgael.com/home

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Space Shooter Challenge: Thruster UI and Cooldown

Using Conda environments for Python, all you need to know

What Do Full Stack, Front End, and Back End Mean?

Gitlab: pipeline to run cross multiple projects

MS in US Career Opportunities For Computer Science / ECE Students

Can I learn Python in a month?

Steps to install Kubernetes in an on Premise Ubuntu server.

Deploy a Production Ready Vault Cluster on AWS in ~5 Minutes

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Gaël Duval

Gaël Duval

Hey 👋 I'm Gaël Duval, freelance Fullstack Developer and UI - UX Designer from France (Paris) ! https://duvalgael.com/home

More from Medium

Git Rebase vs Git Merge

Common Git Workflows You Should Know

Importance of Linux OS for DevOps Engineer

Git Commands I use everyday as a Software Engineer