DEV Community

Cover image for Unique Git Commands You Should Know!
Sriparno Roy
Sriparno Roy

Posted on • Originally published at sriparno.hashnode.dev

Unique Git Commands You Should Know!

Introduction

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

The git commit -am command is a combination of the command git commit and the flags -a and -m. Let's break it down:

The git commit command commits all staged changes to the repository and opens up the default code editor for us to write a commit message.

Image description

The -a flag helps us add and commit all changes to the repository at once.

Image description

The -m flag allows us to write an inline commit message, bypassing the intermediate step of opening up the default code editor.

Image description

Hence, the git commit -am command enables us to add and commit all the changes to the repository at once with an inline commit message. Simple!

Image description

git log --oneline

The git log command displays the commit log of a repository. Each entry contains a commit hash along with the entire commit message.

Image description

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:

Image description

Much better, isn't it?

git branch -m

The git branch command lists all the existing branches in a repository.

Image description

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 git-demo to feature.

Image description

git switch -c

There are generally two steps that you need to follow to checkout a new branch:

  • Use git branch <branch_name> to create a new branch.

  • Use git switch <branch_name> to switch to the newly created branch.

Image description

Good news! You can perform this operation in one step using the git switch -c command.

Image description

git commit --amend

The --amend flag helps you to rewrite the commit message for the last commit.

Image description

Simple, but effective!

Conclusion

Who doesn't want a productivity boost? Using these Git commands will surely provide you with that! Use them and enjoy committing!

Top comments (0)