A Dev’s Thoughts: My Most Used Git Commands

Steffen Pedersen
May 20, 2018 · 3 min read

This is not a full guide to which commands you should learn. I just find it inspiring to read about other developers’ habits and work routines. This I would like to contribute to and tell about my most used Git commands.

I honestly don’t have a specific way on typing these commands. I sometimes write the full command. I sometimes replace git with g. And then I sometimes write the full alias. I think it depends on the goal with the command. It is worth mentioning that I am using ZSH with oh-my-zsh.

Main Commands

These are the commands that I use every day - or almost every day.

If you have heard about Git, then you will probably know these three classic commands. I use them pretty much all the time. It is here that it will be nice to use some aliases. gaa, gcmsg “Add this commit” and gp will come in handy!

These will switch to an existing branch or a new branch. There is not much new going on here. I often use the full aliases here too - gcd and gcb “my-new-branch“.

I always use the option --rebase when I pull from a repository. This will keep my commits nice and clean on the top of the tree. You could use the alias gup. It was a senior developer who taught me the power of rebase.

This will lead us to rebase itself. Remember to rebase! This is especially important if you are doing feature branches. We do not want a half-dead branch, which is a billion commits behind its default branch with merge conflicts up to the throat. Ouch!

It is not that often that I need to merge directly from my terminal. In my team at work we use a branching strategy with feature branches. When a branch should be merged into the default branch (or another), then we use a pull request from GitHub — and the GUI at the website is just fine.

Has your project manager given you a new task, which need to be done quickly? Just throw your current work to the side and focus on the new stuff. It is awesome! I actually don’t use the full alias for this. I am using g instead of git. Maybe it is because I want to be absolutely sure, that I am actually stashing 😀

These are the commands that keeps me updated, and I use them about 500 times a day. I use gss, glg or sometimes glol.

Side Commands

These are the commands that I use occasionally.

This is one of my strange darlings. But why don’t I just use --force? First of all, it is an extremely dangerous command and a huge no-no when using shared branches. It is because it will overwrite the remote repository with whatever you have locally. This can be dangerous if other contributors of the repository have pushed in the meantime. I have mostly used --force-with-lease after a rebase. This is because it works like a safety belt. This article has a great example.

This is actually a command, that I found a few days ago from David Walsh. The command will list the most recently worked on branches from top to bottom. It is so cool!

And if everything goes like 💩, you can always reset the project.


Thank you for your time!

If you liked this, then please 👏 and follow.

Steffen Pedersen

Written by

Hi, my name is Steffen, and I work with the interwebs 💻

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade