A Practical Guide on how to to create your own git command alias

July 07, 2020

Introduction

In this guide, We will learn on how to create some handy command alias.

Example git log command

In previous post Git log commands, we see how we can try various git commit history output.

git log --oneline --graph --decorate

Lets try to create our git command alias, so that we don’t need to type this long command again and again.

Git command alias

Lets create git command alias globally for system.

git config --global alias.nicelog "log --oneline --graph --decorate"

In above command, the keyword alias., is a special keyword. Anything after that will become git alias name after the command.

So, we created a git alias with name nicelog. See, how we can use it.

git nicelog

Now, this will give me output same as if I’m running: git log --oneline --graph --decorate

Modify Git alias

Open ~/.gitconfig file in an editor. You will see a section something like:

[alias]
  nicelog = log --oneline --graph --decorate

Just change the command in that file, save it. Exit.

And, now if you run the command. It will reflect the changes you made.


Similar Posts

Latest Posts