6_woww
Last Updated: July 27, 2016
·
2.659K
· dallas

git command aliases

Here is a list of common git command aliases that I use daily:

alias gfh='git fetch --verbose --prune' # verbose gives you more information about what was fetched; prune removes any remote tracking branches which have been removed from the remote
alias gmg='git merge' # use when you can fast-forward anyway or when you're actually merging 2 different branches together
alias grb='git rebase --verbose' # use when you're pulling down changes from a remote or when pulling in changes to a local-only branch from the branch it branched off of (like from master into a feature branch)
alias gcb='git checkout -b' # need to give it a new branch name, creates the new branch and switches to it
alias gca='git commit --all --verbose' # commits everything (except brand new files and removed files), even unstaged changes
alias gbu='git branch --set-upstream-to' # needs the name of an upstream branch, sets up remote tracking for the local branch (really useful with `gcb` above
alias gap='git add --patch' # goes through each section of diffs and lets you add, skip, edit, split (and more) the lines changed
alias gsh='git stash' # stashes all changes so that your local repo is clean and ready for a merge or rebase
alias gsp='git stash pop' # attempts to pop the most recent stash off the stash stack and apply it to your current local repo; if it fails (due to conflicts) it doesn't remove the stash from the stack
alias gsd='git stash drop' # so in those cases you might need to do this after manually fixing the conflicts :)

I've got many more aliases for git commands, but these are the ones that I find myself using practically every single day :)

9 Responses
Add your response

8885

I prefer have it as a git aliases than as a shell aliases. It is more general then.

over 1 year ago ·
8886

@hauleth, huh, I guess I never really thought about using git aliases (never really read about them when I was learning git). I'll have to look into using those.

over 1 year ago ·
8920

The advantage of using git aliases is that you keep tab-completion of branch names (etc).

over 1 year ago ·
8921

One of the disadvantages, as I see it, is that it's not longer a single 2- or 3-character command; you must always prefix it with git or g and a space, right? (Plus, I rarely use tab-completion for branch names, although that is most likely because it has never worked for me and my aliases :-P)

over 1 year ago ·
8949

What about shell completion? Does bash/zsh understand git aliases?

over 1 year ago ·
8958

@pirj I use ZSH and it does perform auto-completion even with aliases.

over 1 year ago ·
8959

@pirj & @bentruyman: do you have to install a git plugin for ZSH or does it just know git commands and aliases out of the box?

over 1 year ago ·
8994

@dallas: if you haven't seen it already, you should check out scm breeze. It has aliases already defined, but the really nice thing is the index numbers on the changed files.

$gs
[1] file1.txt
[2] file2.txt

Which allows you to do git add files like so:
ga 1-2

over 1 year ago ·
9733

@dallas Oh my ZSH comes with the git plugin installed by default. It also comes prepackaged with git aliases and bash functions.

over 1 year ago ·