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.txt
Letters:
a = add
b = branch
c = commit
Letters with options:
ap = add --patch
be = branch --edit-description
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"
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 branch-name)"
unpublish = "!git push origin :$(git branch-name)"
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.txt
[alias]
s = status -sb
To do your own custom log summaries:
[include]
path = .gitalias.txt
[alias]
l = log --graph --oneline
To do your own custom pretty formatting:
[include]
path = .gitalias.txt
[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://git.wiki.kernel.org/index.php/Aliases
- http://web.archive.org/web/20100911013406/http://stackoverflow.com/questions/267761/what-does-your-gitconfig-contain
- http://web.archive.org/web/20111114085847/http://superuser.com/questions/169695/what-are-your-favorite-git-aliases
- http://stackoverflow.com/questions/1309430/how-to-embed-bash-script-directly-inside-a-git-alias
- http://blog.apiaxle.com/post/handy-git-tips-to-stop-you-getting-fired/
- https://ochronus.com/git-tips-from-the-trenches/
- http://mislav.uniqpath.com/2010/07/git-tips/
- https://github.com/WuTheFWasThat/dotfiles/blob/master/gitconfig
- https://gist.github.com/felipesabino/6391408
- Human Git Aliases
References:
To do list in priority order:
-
Create an alias that helps remove problem files, akin to
bfg
. -
Create installable packages such as for
apt
,brew
,dnf
. -
Create completion file for
bash
,zsh
, etc. -
Create CI/CD pipeline.
-
Create security checksum.
-
Create announcement list.
-
Request comments from git thought leaders.
-
Create aliases for GitPrime metrics suggestions: unreviewed pull requests, new work percentage, legacy refactor percentage, active days, time to first comment, churn, time to resolve.
Thanks to all the contributors, including all the creators of the projects mentioned above.
Thanks to these people for extra help, in order of participation:
- Joel Parker Henderson
- Bill Lazar
- Oleg Broytman
- Alberto Gregorio
- Romain Dartigues
- Joe Nelson
- Scott Lindsay
- baudtack
- Ruben Verborgh
- Rob Kennedy
- Corey Haines
- Mislav Marohnić
- Gary Bernhardt
- Joe Nelson
- Rob Miller
- Michal Jarosz
- Nick Palmer
- Michael Mior
- Nick Kirby
- Berkin Berkcan Çırak
- Erik Martin-Dorel
- Tsukasa Noguchi
- YantaoZhao
- Jeff Wu
- Gareth Owen