Aliases
Stop working so hard! In this chapter, we will look at Git aliases, which greatly reduce the amount of typing you have to do. Aliases can be very simple, or they can take arguments and flags.
Stop working so hard! In this chapter, we will look at Git aliases, which greatly reduce the amount of typing you have to do. Aliases can be very simple, or they can take arguments and flags.
Aliases they allow you to create shortcuts to git
commands. For example, I have the alias st
, which stands for status. Thus, I enter:
git st
and it is exactly as if I had entered:
git status
We'll get to more exciting and useful aliases in just a moment, but first let's look at how these are created. To create an alias:
git
config
--global
alias
followed by a period and then the alias itselfThis sounds more complicated than it is. For example, to create the st
alias, I entered:
git config --global alias.st status
Of course, you don't have to use global
. Your alternatives are system
and local
, but personally, I always use global
because I'm the only one on this computer and I want it to always be available.
Here is a slightly more complicated alias that allows you to create a branch and...
Aliases are a convenient way to shorten otherwise lengthy commands. You create an alias with this sequence:
git
config
--global
You can access the configuration file directly with:
git config --edit --global
Aliases are simple, easy, and incredibly useful when working at the command line.
Create an alias that replaces the following command:
git log ––name-only --oneline
To do this, I will go to the command line and enter:
git config --global alias.nx "log --name-only --oneline"
The double quotes are needed because you are using two flags on log
.
The result of calling this command is shown in Figure 8.2:
Figure 8.2: Our new alias at work
Notice that each commit is there, represented on a single line and with only the SHA and message (except when there is a tag or pointers, as shown on line 1 and line 7 in Figure 8.2).