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"
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"
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>
For example:
git rev-list --count main
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>
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
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"
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
For support and reach out, you can find me on Twitter or LinkedIn.