ππ» Hey, there
First of all, get your favorite drink, prepare your .gitconfig
, and come with me through this huge valley called "Git"...
Git is constantly present in our routine as developers, and a good approach to use this tool is essential. For this case β and any else β there is Git Alias.
π€ What is it?
A Git Alias is simply as a shortcut to other command used in Git CLI. In one fast and abstract comparation, the complete command from Git looks like the functionality of Copy something using the right button from mouse, and a Git Alias is the Ctrl + C
shortcut.
β Why?
Because you are able to save time using this shortcuts, and with specifics settings some commands that are naturally long will be reduced to one keyword.
With a simple example, you will be able to turn this:
git remote add origin https://github.com/user/repository.git
Into this:
git remo https://github.com/user/repository.git
β In this case, I have set remo
as a alias from remote add origin
, but the name of it can be any word you wish.
π Here we go...
Find the configuration file
First of all, it is necessary to find the configuration file from Git, in your machine.
Windows
# To set the config for one user only
C:\Users\{your_user}\.gitconfig
# To set the config for all the users from machine
C:\Program Files\Git\etc\gitconfig
Unix
# To set the config for one user only
~/.gitconfig
# or
~/.config/git/config
# To set the config for all the users from machine
/etc/gitconfig
Set the Aliases
Open the file with an IDE by your preference, and start to set shortcut for commands you need. Before set the first keyword, type [alias]
, indent, and then you are able to set shortcuts. For example:
[alias]
ad = add .
remo = remote add origin
rem = remote add
β‘ Aliases I use
To save time, you can copy and paste the aliases I use, and then change each of them by your preference.
[alias]
ad = add .
remo = remote add origin
rem = remote add
ci = commit -m
pm = push origin master
po = push origin
plm = pull origin master
pl = pull origin
co = checkout
cm = checkout master
cb = checkout -b
st = status -sb
sf = show --name-only
lg = log --pretty=format:'%Cred%h%Creset %C(bold)%cr%Creset %Cgreen<%an>%Creset %s' --max-count=30
incoming = !(git fetch --quiet && git log --pretty=format:'%C(yellow)%h %C(white)- %C(red)%an %C(white)- %C(cyan)%d%Creset %s %C(white)- %ar%Creset' ..@{u})
outgoing = !(git fetch --quiet && git log --pretty=format:'%C(yellow)%h %C(white)- %C(red)%an %C(white)- %C(cyan)%d%Creset %s %C(white)- %ar%Creset' @{u}..)
unstage = reset HEAD --
undo = checkout --
rollback = reset --soft HEAD~1
π Conclusion
Git Alias is a huge friend of our productivity, and surely will help you in your daily commits. For more information about this tool, check the official documentation, or the complete guide of Git.
Top comments (0)