DEV Community

Five Git commands I started using that might be helpful to you

Mike Ekkel on May 30, 2020

Git is a powerful tool I use every single day. Up until a few months ago I only used the bare minimum to get my job done. When I moved to a diffe...
Collapse
 
hakobyansen profile image
Senik Hakobyan

Great post!

Sometimes I need checkout to specific tag. Here's how you can do that:
git fetch --all --tags
git checkout tags/<tag>

You can also create a new branch for the tag:
git checkout tags/<tag> -b <branch-name>

Collapse
 
murkrage profile image
Mike Ekkel

I don't often use tag, but I really like the use cases for tagging version releases. If you ever need to pick something from a specific version, you can just hop into the tag!

Great addition :)

Collapse
 
hakobyansen profile image
Senik Hakobyan

Exactly!

It's useful for debugging purposes, when different versions of the project are deployed to different servers, and you're getting bug report which might be already fixed in the new version. 😀

Collapse
 
marounmaroun profile image
Maroun Maroun

Since Git 2.23.0, you can use git restore. It's a huge improvement over the sometimes-misleading checkout command.

Collapse
 
murkrage profile image
Mike Ekkel • Edited

In what way would you say checkout is misleading? I'd love to dive into that 😄

I did a quick search for git restore and it seems it's still experimental, so I wonder if it's a good idea to advice that. I'll definitely try it out the next time I need it, tho!

Collapse
 
marounmaroun profile image
Maroun Maroun

Sorry for the confusion.

I said "misleading" in the sense that it's used for various purposes - Using checkout you can:

  • Create a branch (with the -b flag)
  • Switch to a branch
  • Reset and revert file

Now, you can use git switch and git restore to avoid such confusion with the checkout command - switch -c creates a branch, switch switches to a branch, and restore is for reverting.

Thread Thread
 
murkrage profile image
Mike Ekkel

Yeah that makes more sense! I get what you are saying and I agree that having the specific command is much clearer. I'm still a little thrown off by the experimental part of the command. All in due time I suppose :)

Collapse
 
0xdonut profile image
Mr F.

This one is golden, thanks :)

git commit --amend --no-edit

Collapse
 
amitavroy7 profile image
Amitav Roy

I agree.. this one is golden. And I am sure, now I am going to use this a lot.

Collapse
 
digianpaul profile image
Paul DiGian

The most enlighting command I find out not so long ago is git add -p ...then whatever... it let you add single chunks of files to stage areas.

It is a godsend when working on complex problems. You can add related chunks in the same commit between files. So commits are still atomic and related to a single change.

Collapse
 
terkwood profile image
Felix Terkhorn

Your list is well-assembled! Thanks!

Collapse
 
murkrage profile image
Mike Ekkel

Thank you very much :)