Now that’s we’ve trudged through part 1, it is time to see how to make this a little easier on us.
Who is this for?
This is for anyone who uses Git, but doesn’t know how to use Aliases. I cover what aliases are, and how to use them.
Aliases
In our last part, we introduced the git commit
command, and noted that we could shorten the number of commands we had to use by using the -a
flag, and the -m
option. Typing
git commit -a -m "Commit message"
every time is error prone, and just is a lot of characters. There’s a way we can shorten this considerably using aliases which are git’s version of shortcuts.
Creating an alias
Creating an alias is just a matter of defining it in your config file. There are two config files: a global one, and a local one. Normally, you will define them in your global one so they’re available across all your repositories. Your config file can be changed from the command line of any repository, so let’s examine the form of the command, and define a couple to shorten some sequences. Here is the form: git config --global alias.{shortcut} "command"
.
Example
Let’s shorten up the git status
to just git st
. Here’s the code that we need to run git config --global alias.st "status"
. Done. Now, whenever we want to run the git status
, git st
will do. Next, we will do the git commit -a -m "Commit Message"
command: git config --global alias.cma "commit -a -m"
. Now, if we wish to create a commit with all modified files, we simply run the command git cma "Commit message here."
.