Jonathan Irvin
Posted on July 20, 2018
First (second) dev.to article! Learn to hit the save button, Jonathan!
You can create aliases both on the repo level and globally just by adding or omitting the --global
flag.
Creating aliases is easy. Just type git config --global alias.co checkout
to create a global alias for git checkout
. Now, all you have to do is type git co develop
. Awesome, right?
Some commands have flags you can add. For example, the checkout
command allows you to optionally create and checkout a new branch with the -b
flag. Git handles these aliases with ease by just surrounding the command with quotes. I like to use cob
for that.
git config --global alias.cob "checkout -b"
Now, to create a new branch, I just type git cob new_branch_name
.
Here are some of my favorite aliases:
st status
co checkout
cob checkout -b
lol log --oneline
If you want to chain commands together, which begin with git
, you have to prefix that with a bang (!).
Say I wanted to stash my changes and do a pull in one command. Let's call this alias "shelve". I would type the following:
git config --global alias.shelve "!git stash && git pull"
I'm liking dev.to so far and I hope to write some more articles. I especially like talking about Git.
Reference: git config
Posted on July 20, 2018
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.