Git - Aliases

From EdWiki

GitLab - Aliases

  • Goals
    Learn how to setup aliases and shortcuts for git commands
  • Common Aliases
    git status, git add, git commit, and git checkout are such common commands that it is useful to have abbreviations for them.
  • Add the following to the .gitconfig file in your $HOME directory.
    File: .gitconfig
  co = checkout
  ci = commit
  st = status
  br = branch
  hist = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short
  type = cat-file -t
  dump = cat-file -p

Now you can type git co wherever you used to have to type git checkout. Likewise with git st for git status and git ci for git commit. And best of all, git hist will allow you to avoid the really long log command.

  • Shell Aliases (Optional)

Note: This section is for folks running a posix-like shell. Windows users and other non-posix shell users can feel free to skip to the next slide.

If your shell supports aliases or shortcuts, then you can add aliases at that level too.

  • File: .profile
alias gs='git status '
alias ga='git add '
alias gb='git branch '
alias gc='git commit'
alias gd='git diff'
alias go='git checkout '
alias gk='gitk --all&'
alias gx='gitx --all'
alias got='git '
alias get='git '

The go abbreviation for git checkout is particularly nice. It allows us to type:

go <branch>

to checkout a particular branch.