Extend your knowledge of git commands

Therese Hagelin
3 min readJun 14, 2021

A few weeks ago, I wrote a story about how useful it is to know your git commands, in which I also described a few commands which can be quite good, or even very good to know. In the same article, I promised to follow up with some more useful commands at a later point. And you know what? Now is the time to have a look at a new bunch of git commands that will make your daily developer life a bit smoother.

Photo of a computer screen
Photo by Morgan Richardson at Unsplash

So let’s deep dive into the world of git then, shall we? This time let’s proceed to some more advanced commands that you might not hear about during your first months of coding.

  1. Git stash

Do you often find yourself in situations where you need to switch between the projects that you’re working on? Then you will absolutely love this command. By typing git stash, the changes you’ve been working on can be stashed/paused until you’re ready to go back to work on that project again. It’s quite common that one has started to work on some code changes, but haven’t had time to get far enough to be ready for a commit. Then it’s absolutely awesome to be able to stash the changes in order to keep them and be able to continue coding at a later point. With the knowledge of how to use git stash, you will never have to feel stressed about losing code changes that you don’t want to commit.

2. Git stash clear

This feels like a good time to bring up this command that can be used after you’ve stashed something. As the command explains quite well, what you will do with it is to remove the changes that you have previously stashed.

There are also a few additional commands related to the git stash. Git stash list will for example give you a list of all the stashed changes and git stash save “message of your choice” allows you to stash the changes along with a message that you choose, which can be quite useful.

3. Git log and a few more detailed ones

At some point you will probably want to view the changes you’ve made and that’s when you’ll benefit from knowing how to use git log. Git log is the general command to view changes made, but you can also use more specified git log commands. If you want to specify what you would like to see in the commit logs, you can for example use git log — summary (with two dashes instead of an emdash) to get the detailed log of the changes or git log — oneline (with two dashes instead of an emdash) to get a shorter version of the commit change logs. It literally gives you the overview of the changes shortened to one line.

4. Git uncommit

Most people get familiar with git commit at a quite early stage, but it’s quite common not being familiar with the opposite; git uncommit. As the name of the command suggests, this will help you if you regret your last commit and want to take it back. A very useful command, that is.

5. Git help

Would you like to get a short explanation of some git command? Then you’re lucky, because there’s actually a command for that purpose as well. Enter git help <command> and you will get your explanation. Could it get any easier? Well, at least it could be more detailed, because you can get even more information if you’re interested. If you add a small character, and instead use the command git help -w <command> you will open a website where you find more information about the command that you’ve specified. Impressive, right?

This starts to feel like the scary movie series named “Jaws” because I can’t imagine this being the last article on this topic. There will definitely be a follow up on this in a few weeks. What can be more exciting than looking into a few new git commands every month? You better tell me, because I sure don’t know 💻

--

--

Therese Hagelin

Product owner with a thorough interest for tech, product management and getting more women involved in the tech business.