How to create git alias by editing .gitconfig
We can create git aliases simply using the git config command.
Example is
git config --global alias.co checkout
But here, we are discussing another method of managing git aliases by editing the .gitconfig file.
Using git aliases will help you to use shorter commands for various operations.
You can create git aliases by following the below steps.
1) Open your .gitconfig from your home folder.
If you are using vim, you can open it by the below command.
vim /home/[user]/.gitconfig
Replace [user] with your username.
You can use any editor.
2)If you already added your email and name to the config, your .gitconfig
will be like
[user]
email = myemail@domain.com
name = myName
Now we have to add a new section [alias]
After that your .gitconfig will be
[user]
email = myemail@domain.com
name = myName
[alias]
3) Now let’s add one alias.
Instead of typing git status, if you would like to use git st
Then we have to add the below line under [alias].
st = status
Now the new .gitconfig will be like
[user]
email = myemail@domain.com
name = myName
[alias]
st = status
4) If you would like to add more aliases,
You can do as shown below.
[user]
email = myemail@domain.com
name = myName
[alias]
st = status
br = branch
co = checkout
pl = pull origin
ps = push origin
plm = pull origin master
psm = push origin master
coi = checkout integration
cob = checkout -b
lbd = branch -D
rbd = push origin –delete
com = commit -m
mg = merge