Six Hidden Git Commands to Simplify Your Workflow
Written on
Discovering Useful Git Commands
While browsing online, I came across several Git commands that can really simplify your workflow. I wish I had known them earlier, as I’ve wasted hours on tasks that these commands could easily handle. Let’s dive in!
Updating Your Last Commit Message
We've all been there—realizing there's a typo in our commit message right after hitting enter. It can be quite annoying and unprofessional. To rectify this, simply use:
git commit --amend -m 'Updated message'
This command allows you to effortlessly modify your last commit message.
Creating a Blank Commit
There are times when you want to make a commit, but no files have been added, modified, or deleted. Previously, I had to change something just to create a commit. Now, that’s a hassle of the past. Use:
git commit --allow-empty -m "No changes made"
This command lets you commit without any changes, which is particularly useful for triggering build processes or starting a new branch.
Combining Staging and Committing
I used to spend a lot of time entering two separate commands for staging and committing changes. Now, I simply use:
git commit -am "commit message"
This command stages all modified files and commits them in one step, saving me a lot of time.
Counting Total Commits
If you want to find out how many commits exist on a specific branch in your repository, you can run:
git rev-list --count <branch-name>
By default, the branch name is main, so for example, you would use:
git rev-list --count main
Git Tutorial in Terminal
If you forget the exact syntax for any command, you can quickly type:
git help tutorial
This will provide you with a basic commands overview, functioning like a quick reference guide. It’s a great time-saver, eliminating the need to search for information online.
If you enjoyed this article and want to read more like it, consider signing up on Medium for just $5 a month. By using my link, I’ll receive a small commission at no extra cost to you.
Chapter 1: Useful Git Commands
The first video, "7 Git Commands You May Not Know," provides an insightful overview of commands that can enhance your Git skills.
Chapter 2: Advanced Git Techniques
In the second video, "10 Must Know Git Commands That Almost Nobody Knows," you’ll discover essential commands that can elevate your Git proficiency.