My Best / Essential Git Aliases. What are your's?
Git Shortcut
============
This is first thing I do. Aliasing git as g
will save a lot of typing. After the symlink creation you can access git with only typing g
in the command line.
$ sudo ln -s `which git` /usr/bin/g
I'm using git now for some years and over the time I came up with a long list of git aliases. Git is great and can give you a great coding experience with it's customizable shortcuts.
The .gitconfig file is located in your home dir. All examples can be added to the [alias] section in this file.
$ nano ~/.gitconfig
Basic Aliases
=============
co = checkout
cp = cherry-pick
p = pull
squash = merge --squash
st = status
df = diff
b = branch
r = reset
Advanced Usage
==============
Revert a file
rv = checkout --
Merging
ours = checkout --ours --
theirs = checkout --theirs --
Stashing
sl = stash list
sa = stash apply
ss = stash save
Danger! Cleanup working dir
This alias will reset all modified files!
cleanup = !git reset --hard && git clean -f
List all aliases
alias = config --get-regexp 'alias.*'
Log One Line
logol = log --pretty=format:"%h\\ %s\\ [%cn]"
Search in files
search = "grep -Iin"
Vagrant
vup = !vagrant up
vsu = !vagrant suspend
vss = !vagrant ssh
vde = !vagrant destroy
vpr = !vagrant provision
If you have other good git aliases feel free to write a comment :-)
Written by Markus Perl
Related protips
9 Responses
Resurrection of lost commits:
zopa = !git log --graph --decorate --pretty=oneline --abbrev-commit --all $(git fsck --no-reflogs | grep commit | cut -d\\ -f3)
sup = git submodule update
for standup (lo is my pretty-print log):
work = !git lo --author bjones --before today --after \"two days ago\" --no-merges
info = !git st && echo && git lo && echo && git remote -v
ca = "commit -a"
dt = difftool --no-prompt
mt = mergetool --no-prompt
pff = pull --ff-only
stashall = !git add -A && git stash
https://coderwall.com/p/vbq-ra - the best are fix
and todo
.
alias.lg=log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
alias.st=status
alias.com=commit -am
My aliases are defined in bashrc:
alias gitlog="git log --color --graph --pretty=format:'%Cgreen[%Creset%h%Cgreen]%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
alias gittoday="git log --color --graph --pretty=format:'%Cgreen[%Creset%h%Cgreen]%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --since=yesterday"
alias commit='git commit'
alias gb='git branch -v'
alias gc='git commit -m'
alias gt='git commit -m "typo"'
alias ga='git add '
alias gd='git diff'
alias gr='git rm'
alias gs='git status'
alias gss='git status -s'
alias gpl='git pull origin'
alias gush='git push origin'
alias gco='git checkout'
alias amend='git commit --amend'
shipit = push heroku master
adhd = commit --amend --reset-author
I am highly fond of Dash for managing git operations. I use the below 'snippet' to save me time and effort; the terms within underscores are variables naturally; Dash fills all the identically-named fields concurrently as you type.
mkdir __repository-name__
cd __repository-name__
git init
git remote add origin git@github-personal:SteveBenner/__repository-name__.git
echo "# Repo and README created using an automated script, bitch\!" >> README.md
git add README.md
git commit -m "Initial commit for git repo stored on Github.com."
git push -u origin master
# publishes local branch to remote origin
pub = "!f() { u=${1:-origin}; ref=`git symbolic-ref HEAD`; read -p \"Push ${ref#refs/heads/} to $u? \" a && [ \"$a\" = \"y\" ] && git push -u $u $ref; }; f"
# Handling files that are to be assumed unchanged.
ignore = update-index --assume-unchanged
uningore = update-index --no-assume-unchanged
ignored = !git ls-files -v | grep '^[a-z]'
# Pull and push from the current branch
sync = "!f(){ local branch=`git branch 2> /dev/null | sed -e '/^[^*]/d' -e \"s/* \\(.*\\)/\\1/\"`; git pull origin $branch && git push origin $branch; }; f"
# Display 'git describe' and latest 5 tags
taggings = "!f(){ echo 'Describe: '; git describe; echo 'Latest 5 tags: '; git tag | sort -V | tail -5; }; f"
# Switch to latest tag
latest-tag = "!f(){ local latest=`git tag | sort -V | tail -1`; git checkout $latest; }; f"