Git commands, you may not know.

Pradumna Saraf - Jan 30 '22 - - Dev Community

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.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player