6 git commands, you may not know.

6 git commands, you may not know.

Pradumna Saraf
·Jan 30, 2022·

2 min read

Subscribe to my newsletter and never miss my upcoming articles

Play this article

Table of contents

  • 1) Updating the last commit message.
  • 2) Blank Commit.
  • 3) Checking the total number of commits.
  • 4) Checking files from different a branch.
  • 5) Staging (adding) and committing the changes in a single command.
  • 6) Git tutorial on the terminal.

Here are some of the top git commands which I handpicked, that can be useful to increase your productivity, and also save your some time.

1) Updating the last commit message.

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

git commit --amend -m "Updated message"

2) Blank Commit.

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

git commit --allow-empty -m "blank commit message"

3) Checking the total number of commits.

If we want to check the total no of the commit on a particular branch we can use this command.

git rev-list --count <branch-name>

Eg:

git rev-list --count main

4) Checking files from different a branch.

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

git show <branch-name>:<file-name>

For Eg: If we are working on the test branch and want to see the README.md file of the main branch, we can use this command:

git show main:README.md

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

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

git commit -am "message"

6) Git tutorial on the terminal.

Yes!,you heard is right, with only single command use can have a whole git tutorial at your fingertips.

git help tutorial

For Support and Reachout: Twitter LinkedIn

Did you find this article valuable?

Support Pradumna Saraf by becoming a sponsor. Any amount is appreciated!

See recent sponsors Learn more about Hashnode Sponsors
 
Share this