Sometimes the alias of the git command is too long, and it is inconvenient to input on the command line. At this time, we can set the command alias.
Set system command aliases
Setting the system command alias can .bash_profile
be configured in the file. This file is also the place where we often configure environment variables. This file itself is invisible. Use the shortcut key comman + shift + .
to view the file. In the Mac system, the file is under the user directory. /Users/sunshiyu/.bash_profile
If there is no such file, it can be created manually, but the system does not allow the creation .
of files starting with . We can create it through the touch command:
touch .bash_profile
You can double-click to open the file for editing, or you can open it directly with the command:
vim ~/.bash_profile
If the command is opened, i
press the key to enter the editing state, press to esc
exit editing after editing, and then press :wq
to save. Then enter the command source ~/.bash_profile
to make the file take effect.
Command line editing is a bit cumbersome. It is recommended to double-click to open and edit directly, which is simple and fast! ! !
# 用于输出git提交日志
alias git-log='git log --pretty=oneline --all --graph --abbrev-commit'
# 用于输出当前目录下所有文件及基本信息
alias ll='ls -al'
After the configuration is completed, closing the file will take effect. At this time, reopen the terminal to verify whether the command alias is effective.
To check the command aliases of the system, use alias
the command:
alias
Above you can see our configuration git-log
and ll
two command aliases.
Set Git command aliases
There are two ways to set the git command alias, one is to configure it in the same way as the system command alias above .bash_profile
, and the other is .gitconfig
to configure it in . .gitconfig
The location of the file and .bash_profile
the same directory
Double-click to open the file for direct editing:
[alias]
lg = "log --pretty=oneline --all --graph --abbrev-commit"
After editing, just close it to enter, and then reopen the terminal to verify whether the command alias is effective.
Above we have configured git to view the command alias of the commit log. The difference is that .bash_profile
the configuration is that the entire git
command has keywords git
, and .gitconfig
the configuration in .git
git
git-log
The effect of the two lg
commands is the same