DEV Community

Al-Amin Islam
Al-Amin Islam

Posted on

6 git commands, you may not know.

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.

Enter fullscreen mode Exit fullscreen mode

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"
Enter fullscreen mode Exit fullscreen mode

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"
Enter fullscreen mode Exit fullscreen mode

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>


Example:


git rev-list --count main

Enter fullscreen mode Exit fullscreen mode

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>
Enter fullscreen mode Exit fullscreen mode

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

Enter fullscreen mode Exit fullscreen mode

5) Staging (adding) and committing the changes in a single command.
Instead of doing git add andgit commit separately, we can use this single command to perform this:

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

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
Enter fullscreen mode Exit fullscreen mode

Share with your friends.

Top comments (0)