善用Git alias 提高工作效率

674 阅读1分钟

背景

Git 并不会在你输入部分命令时自动推断出你想要的命令。 如果不想每次都输入完整的 Git 命令,可以通过 git config 文件来轻松地为每一个命令设置一个别名。

收益

大幅提高效率,比如:

  • git status -> git st
  • git pull --> rebase origin master -> git pr
  • git check out -> git co
  • git branch -> git br

配置别名

  • 输入命令
vim ~/.gitconfig
  • 添加内容
[alias]
        st = status
        co = checkout
        ci = commit
        cim = commit -m
        df = diff
        br = branch
        pr = pull --rebase origin master
        pl = pull
        ps = push
        ct = commit
        lg = log --stat
        lgp = log --stat -p
        lgg = log --graph
        lgga = log --graph --decorate --all
        lgm = log --graph --max-count=10
        lo = log --oneline --decorate       
        lol = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
        lola = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --all    
        log = log --oneline --decorate --graph
        loga = log --oneline --decorate --graph --all

更过优质内容:请点击