Git has definitely become the main version control system developers use lately, and I admit, I got on that bandwagon when I got more into GitHub. I wanted to be more familiar with Git since I was doing more and more with GitHub.
I'll also admit, and I may be dating myself here, my first version control system that I used was StarTeam. Never heard of it? I don't blame you. Just look at the interface it had:
I used that for a few years until the company got rid of that and went to Team Foundation Server. Definitely a step up from StarTeam, but then I got started using Git. The more I use it the more I enjoyed using it.
However, I didn't get an appreciation for how powerful it was at first. I first started using Git when GitHub had their GitHub Desktop applications and used that for a while. I also used SourceTree on one project I was on.
While these applications are great, I still wanted to learn more about the commands these applications are running in the background. That's when I started to only use Git through the command line. From that challenge I set myself, I realized there was way more to Git than these applications may show. Below is a list of commands I've been using quite often, but feel they may not be as well known.
If you ever need to quickly put your current changes away so you can help work on something more important than your current task? Well, git stash is here to the rescue!
Just type in
git stash and your changes are "stashed" away.
Now I can move on to working on something else while keeping my changes away for me to come back to.
You can have many as many stashes as you need, as well. If you're not sure of the ones you have, just do a
git stash list and you'll see them all.
Oh, but you want a meaningful message when you stash to you have an idea what changes are in it? Git has you covered there, too! Just do a
git stash save <message here> and git will save the stash with your message.
So we can save stashes in a couple of different ways, but what if we want to go back to a stash to continue our work? We have a couple of ways to do that, as well.
If you want to just apply the latest stash, just do a
git stash apply.
If we want to apply a specific stash we can just do
git stash apply <stash name>.
Sometimes, you just want to double check the changes you've done before adding and commiting. In that case
git diff is there for that.
No need to go to a separate application just to see what the changes are. You can just look at them in the command line.
With all this said, though, there is still a ton more commands and uses that Git has that I probably have never even heard of. Because of that, as y'all could probably guess, I got a book for it!
I'll definitely be reviewing this after I go through it to let y'all know how it is overall. Just going through the table of contents indicates that it covers a lot of really useful commands.
What git commands can you not live without?