Shortcuts for git commands

前端 未结 6 1261
天命终不由人
天命终不由人 2021-02-05 04:35

I would like to use shortcuts or aliases for git commands.

git diff
git status
git push 
git pull
git stash
git branch -a

How do I create shor

6条回答
  •  眼角桃花
    2021-02-05 05:11

    I would recommend oh-my-zsh git shortcuts.

    It has a very thorough (more than 100 shortcuts) list.

    Here is a small sample to get you started:

    alias ga='git add'
    alias gc='git commit -v'
    alias gd='git diff'
    alias gst='git status'
    
    alias gco='git checkout'
    alias gcm='git checkout master'
    
    alias gb='git branch'
    # view remote branches
    alias gbr='git branch --remote'
    
    alias gup='git pull --rebase'
    alias gp='git push'
    # push a newly created local branch to origin
    alias gpsup='git push --set-upstream origin $(git_current_branch)'
    

    The selection of letters in most shortcuts make them adequately intuitive.

    Using the shortcuts provided by a popular and active open source project has many benefits. Some of which:

    • never care if you lose them since you can easily find them!
    • increases the chances of other people having the same shortcuts as you and thus learn from each other.
    • decreases the chances of shortcuts conflicting with other commands.

    Even if you don't use zsh, you can still copy them in a regular shell configuration file like .bashrc.

    I have also added

    alias oh='less ~/.oh-my-zsh/plugins/git/git.plugin.zsh'
    

    so that I can quickly read the available shortcuts right from the terminal.

提交回复
热议问题