Skip to content

Git alias commands for faster easier version control

Notifications You must be signed in to change notification settings

apurva-koti/gitalias

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 

Repository files navigation

Git Alias

This project provides many git alias commands that you can use as you like.

Contents:

Introduction

What is Git Alias?

Git Alias is a collection of git version control shortcuts, functions, and commands:

  • Shortcuts such as s for status.

  • Improvements such as optimize to do a prune and repack with recommended settings.

  • Topic workflows such as topic-start to create a new topic branch for a feature or fix.

  • Visualizations such as graphviz to show logs and charts using third-party tools.

Where is the code?

To see the complete code, view this file:

Why use this?

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.

Install

Download the file gitalias.txt:

curl -O https://raw.githubusercontent.com/GitAlias/gitalias/master/gitalias.txt

Typical usage for a typical user:

  • Save this file as a dot file in your home directory: ~/.gitalias.txt

  • git config --global include.path ~/.gitalias.txt in terminal. Or manually edit your git config dot file in your home directory such as ~/.gitconfig, include the path to this file.

Example file ~/.gitconfig with an entry to include the file ~/.gitalias.txt:

[include]
  path = gitalias.txt

Examples

Shortcut examples

Letters:

a = add
b = branch
c = commit

Letters with options:

ap = add --patch
be = branch --edit-description
ci = commit --interactive

Popular examples

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}

Accelerator examples

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'"

Recovery examples

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"

Coordination examples

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}..

Workflow examples

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"

Optimization examples

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"

Customization

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.

Status

To do your own custom terse status messages:

[include]
   path = .gitalias.txt
[alias]
  s = status -sb

Log

To do your own custom log summaries:

[include]
   path = .gitalias.txt
[alias]
  l = log --graph --oneline

Format

To do your own custom pretty formatting:

[include]
   path = .gitalias.txt
[format]
  pretty = "%H %ci %ce %ae %d %s"

Epilog

See also

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:

References:

To do

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

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:

About

Git alias commands for faster easier version control

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published