Git aliases and profiles

Time:2022-1-14

remarks:

This article refers to teacher Liao Xuefeng’s blogGit tutorial。 Learn and record according to his blog. Thank him for his selfless sharing. You are also welcome to check the original text.

Configure alias

If so, the GIT version control system of the artifact can simplify the command. such asgit status, direct usegit stInstead, it’s amazing.

This can be achieved by configuring aliases for git commandsstexpressstatus, as follows:

$ git config --global alias.st status

heregit stJust saygit status

This simplifies more commands, such ascoexpresscheckoutciexpresscommitbrexpressbranch

$ git config --global alias.co checkout
$ git config --global alias.ci commit
$ git config --global alias.br branch

In this way, the submission can be abbreviated as follows:

$ git ci -m "bala bala bala..."

parameter--globalIs a global parameter. The configured alias can be used under the current computer.

  • unstagealias

Another example is to undo the command to modify the staging areagit reset HEAD fileIt’s aunstageOperation, you canunstageAlias:

$ git config --global alias.unstage 'reset HEAD'
  • git lastalias

Such as configurationgit last, display the last submission information:

$ git config --global alias.last 'log -1'

In this way, the latest submission can be displayed with git last:

Some people even madly configured LG to:

git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"

git lgYou can use different colors to identify log records, which looks very dazzling

configuration file

Git configuration, plus--globalIt works for the current user. If it is not added, it only works for the current warehouse.

  • Location of GIT configuration file

Git configuration files for each warehouse are placed in.git/configIn the file:

The following is what Mr. Liao Xuefeng showed in his blogconfigFile content

$ cat .git/config
[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    ignorecase = true
    precomposeunicode = true
[remote "origin"]
    url = [email protected]:michaelliao/learngit.git
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
    remote = origin
    merge = refs/heads/master
[alias]
    last = log -1

[alias]It is an alias configuration item. To delete an alias, delete the corresponding line directly.

The GIT configuration file of the current user is placed under the user’s home directory.gitconfigfileYes.

Linux system user directoryhomeView under directory
The windows user directory isC: C: \ users \ user name, pass%USERPROFILE%or%HOMEPATH%Direct access

$ cat .gitconfig
[user]
        name = Your Name
        email = [email protected]
[core]
        autocrlf = false
[filter "lfs"]
        clean = git-lfs clean -- %f
        smudge = git-lfs smudge -- %f
        process = git-lfs filter-process
        required = true