Shortcuts for git commands

前端 未结 6 1113
天命终不由人
天命终不由人 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 04:58
    git config --global alias.<short> <long>
    

    e.g.

    git config --global alias.cob "checkout -b"
    

    (Without --global, you get per-project aliases.)

    0 讨论(0)
  • 2021-02-05 04:58

    More than one way to do this. Explained below with examples:

    [1] Using the "alias" option provided by the git itself.

    Example: git config --global alias.co checkout

    Usage hence: git co

    This is equivalent to making entries manually in the '~/.gitconfig' (this path since, --global is used, otherwise the .gitconfig file of the project, in which you attempting to set will be used).

    [alias]
      co = checkout
    

    Therefore, manually making entry to the file, as specified can also be another way of setting your aliases.

    for more Info

    [2] Using .bash_profile/.bashrc.

    Edit your ~/.bash_profile or ~/.bashrc, as below:

    Example: alias go='git checkout'

    Usage hence: go

    (Do not forget to 'source ~/.bash_profile' or 'source ~/.bashrc' after the changes to the file, based on your case).

    for more Info

    So, if you clearly see, the second way is to further put the shorthand/aliases to the git-command usage (for your profile).

    Also, the aliases meant for ease of usability, hence what you prefer/at ease, is what you can add (like: i can say probably, Giraffe = git checkout, if that is my ease).

    0 讨论(0)
  • 2021-02-05 04:59

    I made a terminal "Mode" for bash called git_mode in order to avoid typing git and use c for commit and so forth.

    You can find it here.

    Sample commands look like:

    # Add
    alias a='git add'
    alias add='git add'
    
    # Diff
    alias d='git diff'
    alias diff='git diff'
    
    # Grep/Search
    alias search='git grep'
    alias grep='git grep'
    
    # Merge
    alias merge='git merge'
    alias m='git merge'
    
    # Branch
    alias b='git branch'
    
    # Status
    alias s='git status'
    alias status='git status'
    
    # Commit
    alias c='git commit'
    alias commit='git commit'
    
    # Remote
    alias remote='git remote'
    
    # Pull
    alias pull='git pull'
    
    # Push
    alias push='git push'
    
    # init
    alias init='git init'
    alias i='git init'
    
    # clone
    alias clone='git clone'
    
    # checkout
    alias ch='git checkout'
    alias checkout='git checkout'
    
    # stash
    alias stash='git stash'
    
    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2021-02-05 05:16

    Put this into your .gitconfig

    [alias]
      st = status
      ci = commit
      br = branch
      co = checkout
    

    You can add as much as you want

    0 讨论(0)
  • 2021-02-05 05:22

    I use this library, SCM Breeze. It gives really cool UI for files and easy to use.

    0 讨论(0)
提交回复
热议问题