DEV Community

Cover image for Git commands, you may not know.
Pradumna Saraf
Pradumna Saraf

Posted on • Edited on

Git commands, you may not know.

Here are some of the top git commands that I handpicked, which can be useful for increasing your productivity and saving you time.

1) Updating the last commit message

If you want to update the message of your last commit because it didn't look conventional or meaningful, use this command to edit it:

git commit --amend -m "Updated message"
Enter fullscreen mode Exit fullscreen mode

2) Blank Commit

Sometimes we need a blank commit (no changes added or deleted), maybe to initialize our repository or trigger some kind of action. We can use this command:

git commit --allow-empty -m "blank commit message"
Enter fullscreen mode Exit fullscreen mode

3) Checking the total number of commits

If you want to check the total number of commits on a particular branch, you can use this command:

git rev-list --count <branch-name>
Enter fullscreen mode Exit fullscreen mode

For example:

git rev-list --count main
Enter fullscreen mode Exit fullscreen mode

4) Checking files from a different branch

If you want to view some files from a different branch while working on a different branch, you can use this command:

git show <branch-name>:<file-name>
Enter fullscreen mode Exit fullscreen mode

For example, if you are working on the test branch and want to see the README.md file from the main branch, you can use this command:

git show main:README.md
Enter fullscreen mode Exit fullscreen mode

5) Staging (adding) and committing changes in a single command

Instead of doing git add and git commit separately, you can use this single command to perform both actions:

git commit -am "message"
Enter fullscreen mode Exit fullscreen mode

6) Git tutorial on the terminal

Yes! You heard it right. With only a single command, you can have a whole git tutorial at your fingertips.

git help tutorial
Enter fullscreen mode Exit fullscreen mode

For support and reach out, you can find me on Twitter or LinkedIn.

Top comments (7)

Collapse
 
0xmukesh profile image
Mukesh

Great post, Pradumna 🚀

Collapse
 
pradumnasaraf profile image
Pradumna Saraf

Thanks, Kira!

Collapse
 
khazifire profile image
khazifire

I have always wanted to know how to update a previous commit message, thank you for sharing now i know

Collapse
 
pradumnasaraf profile image
Pradumna Saraf

Thank you for reading it

Collapse
 
tkxel_software_outsourcing profile image
Arslan Ijaz

Amazing post

Collapse
 
pradumnasaraf profile image
Pradumna Saraf

Thanks for reading it :)

Collapse
 
thumbone profile image
Info Comment hidden by post author - thread only accessible via permalink
Bernd Wechner

Staging not Stagging ;-). Fixe that quickly and delete this commen (quick quality improvement feedback). Nice little summary otherwise. Thanks.

Some comments have been hidden by the post's author - find out more