Unique Git Commands You Should Know!
Tags: opensource, git, github
Published: 2023-03-05 05:30:00

## 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7ixcz0aywr3ublqi0glo.png)


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


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wzlerqu3e1mrd2z1oexk.png)



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


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kmw5iu0g8k6zzs0xqvpp.png)


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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/09tzvt5kh6823kulu8yz.png)



## 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vkkhjfo52yltd4bo3zfu.png)



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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lx82pnii2mq22ynd7ao3.png)



Much better, isn't it?

## git branch -m

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


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b2psszkh2et72lz223vo.png)



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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/180fx9k1x0zdk4fzcquy.png)



## 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b9chjd42aanfyo15b506.png)



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


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j0zg45jzupusclladdxj.png)



## git commit --amend

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


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7s16r238gauwa8ymuopc.png)


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!