Git Alias Configuration
Learn to create aliases in Git.
We'll cover the following
What is an alias?
If a command is very long, we can set an alias command for it. We do this by setting the alias in the config
file in the .git
folder.
There are several places where we can put the config
file. Most likely, we’ll want to create this file in our home directory. That applies to all terminals on our machine and projects under our user account.
For example, here’s an alias to show all branches with one-line log commits and graph view:
[alias]
st = status
ll = log --all --oneline --graph --decorate --color
There are two methods by which we can set an alias. Each method is explained below.
First method
-
In the main
SampleFolder
, run thels -a
command to see all the hidden files and folders. -
We see a folder named
.git
. Move into that folder using thecd .git
command. -
Use the
ls -a
command again to see all files. -
Write the lines mentioned above in the
config
file using any editor orecho
command:$ ls -a $ cd .git $ ls -a $ echo [alias] >> config $ echo st = status >> config $ echo ll = log --all --oneline --graph --decorate --color >> config
-
Next, come back to the main folder using the
cd .
command. -
In the
SampleProject
folder, run the commands below to confirm the results:$ git status $ git st $ git log --all --oneline --graph --decorate --color $ git ll
The output of the first two and the last two commands should be consistent. If an alias isn’t made, it gives an error that no such command exists in Git.
Get hands-on with 1200+ tech skills courses.