Git is a free and open-source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.
If you know Git and are interested in learning some unique Git commands that will make your day-to-day life easier, then this article is for you. Let's start!
git commit -am command is a combination of the command
git commit and the flags
-m. Let's break it down:
git commit command commits all staged changes to the repository and opens up the default code editor for us to write a commit message.
-a flag helps us add and commit all changes to the repository at once.
-m flag allows us to write an inline commit message, bypassing the intermediate step of opening up the default code editor.
git commit -am command enables us to add and commit all the changes to the repository at once with an inline commit message. Simple!
git log command displays the commit log of a repository. Each entry contains a commit hash along with the entire commit message.
Technically, it is absolutely fine. But visually, it would look a lot nicer if we somehow managed to restrict each entry to a single line. Guess what, the
--oneline flag does exactly that! Take a look at the below screenshot:
Much better, isn't it?
git branch command lists all the existing branches in a repository.
Suppose you have messed up the name of a branch and you want to rename it. Can you do it?
Yes! Appending the
-m flag to the
git branch command helps you rename a branch. In our case, we renamed
There are generally two steps that you need to follow to checkout a new branch:
git branch <branch_name>to create a new branch.
git switch <branch_name>to switch to the newly created branch.
Good news! You can perform this operation in one step using the
git switch -c command.
--amend flag helps you to rewrite the commit message for the last commit.
Simple, but effective!
Who doesn't want a productivity boost? Using these Git commands will surely provide you with that! Use them and enjoy committing!