I learned some git tricks from the website: 廖雪峰的官方网站. Unfortunately the posts in the website are all writen in Chinese, therefore I would like to share them here in English.
Git Alias
We use some git commands such as git status
a lot. It is often annoying to redo hundreds of times because of typos when we type this word status
.git st
is much easiser than git status
, we like lazy solutions.
All we need to do is typing one command line, telling git that thereafter st
is the alias of status
:
Now just try typing git st
and see if it works.
There are other commands that can be abbreviated, it is commonly used that co
for checkout
, ci
for commit
and br
for branch
:
Since then, a commit command can be simplified as:
In the git config
commands above, --global
option means that the parameters are used globally, and are available in all repositories within the same user account in the computer.
Besides, alias is also used for custom git commands. For example, let’s set up a git last
command showing last single commit log:
Using git last
to show the latest commit information:
Behold, well, check this out:
The output of git lg
:
Dang, why didn’t I know about this before?
Alias Config File
While configuring git, attaching --global
option makes it effective to current user, otherwise it will only be effective within currect repository.
Where do all these configurations go? For each repository, configurations are stored in file .git/config
:
Current alias configurations are written in [alias]
.
For global cofigurations, they are stored in an invisible file under main folder ~/.gitconfig
:
We can directly modify content in this file to configure alias settings or other personal customizations.
We Are Lazy
We are lazy, so we utilize all we could to minimize our labor XD.