This project provides many git alias commands that you can use as you like.
Contents:
Git Alias is a collection of git version control shortcuts, functions, and commands:
-
Shortcuts such as
s
forstatus
. -
Improvements such as
optimize
to do a prune and repack with recommended settings. -
Workflows such as
topic-start
to create a new topic branch for a new feature. -
Visualizations such as
graphviz
to show logs and charts using third-party tools.
To see the complete code, view this file:
We are creating this alias list because we type these commands many times daily, and we want the commands to be fast and also accurate.
We often work on teams, across many companies and organizations, and using multiple shells. We want to count on a set of aliases. For shorter commands, such as s
for status
, fast speed is nice. For longer commands, such as repacker
, accurate settings are important.
Download the file gitalias.txt
and include it:
curl https://raw.githubusercontent.com/GitAlias/gitalias/master/gitalias.txt -o ~/.gitalias
git config --global include.path ~/.gitalias
Download the file gitalias.txt
any way you want, such as:
curl -O https://raw.githubusercontent.com/GitAlias/gitalias/master/gitalias.txt
Manually edit your git config dot file any way you want, such as:
vi ~/.gitconfig
Include the path to this file:
[include]
path = ~/.gitalias
Letters:
a = add
b = branch
c = commit
Letters with options:
ap = add --patch
bm = branch --merged
ci = commit --interactive
Summarizing:
dd = diff --check --dirstat --find-copies --find-renames --histogram --color
ll = log --graph --topo-order --abbrev-commit --date=short --decorate --all --boundary --pretty=format:'%Cgreen%ad %Cred%h%Creset -%C(yellow)%d%Creset %s %Cblue[%cn]%Creset %Cblue%G?%Creset'
Committing:
cam = commit --amend --message
rbi = rebase --interactive @{upstream}
Logging:
log-graph = log --graph --all --decorate --oneline
log-my-week = !git log --author $(git config user.email) --since "1 week ago"
Searching:
grep-group = grep --break --heading --line-number
grep-all = !"git rev-list --all | xargs git grep '$1'"
Backtracking:
uncommit = reset --soft HEAD~1
cleanout = !git clean -df && git checkout -- .
Preserving:
snapshot = !git stash push "snapshot: $(date)" && git stash apply "stash@{0}"
archive = !"f() { top=$(rev-parse --show-toplevel); cd $top; tar cvf $top.tar $top ; }; f"
Find the branch's previous commit hash:
git branch-commit-prev
Find the branch's next commit hash:
git branch-commit-next
Combining:
ours = !"f() { git checkout --ours $@ && git add $@; }; f"
theirs = !"f() { git checkout --theirs $@ && git add $@; }; f"
Comparing:
incoming = !git remote update --prune; git log ..@{upstream}
outgoing = log @{upstream}..
Synchronizing:
get = !git fetch --prune && git pull --rebase=preserve && git submodule update --init --recursive
put = !git commit --all && git push
Publishing:
publish = "!git push -u origin $(git current-branch)"
unpublish = "!git push origin :$(git current-branch)"
Branching:
topic-start = "!f(){ b=$1; git checkout master; git fetch; git rebase; git checkout -b "$b" master; };f"
topic-stop = "!f(){ b=$1; git checkout master; git branch -d "$b"; git push origin ":$b"; };f"
Naming:
top-name = rev-parse --show-toplevel
branch-name = rev-parse --abbrev-ref HEAD
upstream-name = !git for-each-ref --format='%(upstream:short)' $(git symbolic-ref -q HEAD)
Pluralizing:
branches = branch -a
stashes = stash list
tags = tag -n1 --list
Streamlining:
pruner = !git prune --expire=now; git reflog expire --expire-unreachable=now --rewrite --all
repacker = !git repack -a -d -f --depth=300 --window=300 --window-memory=1g
expunge = !"f() { git filter-branch --force --index-filter \"git rm --cached --ignore-unmatch $1\" --prune-empty --tag-name-filter cat -- --all }; f"
If you want to use this file, and also want to change some of the items, then one way is to use your git config file to include this gitalias file, and also define your own alias items; a later alias takes precedence.
This section has examples that include this file, then add a customization.
To do your own custom terse status messages:
[include]
path = ~/.gitalias
[alias]
s = status -sb
To do your own custom log summaries:
[include]
path = ~/.gitalias
[alias]
l = log --graph --oneline
To do your own custom pretty formatting:
[include]
path = ~/.gitalias
[format]
pretty = "%H %ci %ce %ae %d %s"
Typically a short alias for a command and its options is in the same order as the command and option words:
-
Right:
fab = foo --alpha --bravo
-
Wrong:
baf = foo --alpha --bravo
-
Wrong:
abf = foo --alpha --bravo
Typically a short alias for a command and its options uses the first letter of each option word:
-
Right:
fab = foo --alpha-bravo
-
Wrong:
fa = foo --alpha-bravo
-
Wrong:
fb = foo --alpha-bravo
More ideas for git improvements:
-
If you want to alias the git command, then use your shell, such as
alias g=git
. -
If you want history views, see git-recall
-
If you use
oh-my-zsh
, then you may like the git plugin -
If you use
vim
then see Fugitive -
If you use
emacs
then see Magit -
If you use git shell scripting then see SCM Breeze
-
If you use
node
then see git-alias
For more git config ideas, and for credit for many of the aliases here, please see these excelent resources:
-
https://stackoverflow.com/questions/1309430/how-to-embed-bash-script-directly-inside-a-git-alias
-
https://blog.apiaxle.com/post/handy-git-tips-to-stop-you-getting-fired/
-
https://github.com/WuTheFWasThat/dotfiles/blob/master/gitconfig
References:
Thanks to all the contributors, including all the creators of the projects mentioned above.
Thanks to these people for extra help, in alphabetic order:
- Alberto Gregorio
- Berkin Berkcan Çırak
- Bill Lazar
- Corey Haines
- Erik Martin-Dorel
- Gareth Owen
- Gary Bernhardt
- Jeff Wu
- Joe Nelson
- Joe Nelson
- Joel Parker Henderson
- Kobus Jooste
- Michael Mior
- Michal Jarosz
- Mislav Marohnić
- Nariyasu Heseri
- Nick Kirby
- Nick Palmer
- Oleg Broytman
- Rob Kennedy
- Rob Miller
- Romain Dartigues
- Ruben Verborgh
- Scott Lindsay
- Tsukasa Noguchi
- YantaoZhao
- baudtack