Skip to content

Instantly share code, notes, and snippets.

@Camwyn
Last active July 29, 2020 15:19
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Camwyn/b2671739a82275d8375c to your computer and use it in GitHub Desktop.
Save Camwyn/b2671739a82275d8375c to your computer and use it in GitHub Desktop.
My aliases for git
[alias]
# archive a branch
ab = !sh -c 'git checkout $1 && git pull && git tag archive/$1 && git push origin $1 && git push origin archive/$1 && git checkout master && git branch -D $1 && git push origin --delete $1' -
# archive a branch (to a remote other than origin)
abb = !sh -c 'git checkout $1 && git pull $2 $1 && git tag archive/$1 && git push $2 $1 && git push $2 archive/$1 && git checkout master && git branch -D $1 && git push $2 --delete $1' -
# list aliases
aliases = !git config --get-regexp 'alias.*' | colrm 1 6 | sed 's/[ ]/ = /'
# list branches
br = branch
# show current branch - tried to use to get branch name for other aliases
bn = !git rev-parse --abbrev-ref HEAD
# git commit
cm = commit
# git add --all && git commit
cma = !sh -c 'git add --all && git commit -a' -
# git checkout
co = checkout
# create/checkout new branch
cob = checkout -b
# delete branch
del = !sh -c 'git branch -D $1' -
# git diff
df = diff
# show last commit details
last = cat-file commit HEAD
# colorful git log - should delete this, I don't really use it much
lg = log --graph --all --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative
mg = merge
# merge into master, no fast-forward
mm = !sh -c 'git checkout master && git pull && git merge --no-ff $1' -
# merge no fast-forward
mn = merge --no-ff
# pull and merge no fast-forward
mp = !sh -c 'git pull && git merge --no-ff $1' -
# add files to last commit - no message change
moar = !sh -c 'git add --all && git commit --amend --no-edit' -
# merge (no fast-forward) and then show status
ms = !sh -c 'git merge --no-ff && git st'
# show new commits
new = !sh -c 'git log $1@{1}..$1@{0} "$@"'
# set origin no push - for when working with a fork and you don't want to accidentally push to origin
nopush = git remote set-url --push origin no_push
# push a new branch
pub = !sh -c 'git push -u origin $( git rev-parse --abbrev-ref HEAD )'
# git status
st = status
# update submodules recursively
sub = submodule update --init --recursive
# svn push - for Automattic's VIP
svnp = !sh -c 'svn commit -m "\"$1\"" && git push origin master' -
# unstage all added files
unstage = reset HEAD
# remove file from git tracking
untrack = !sh -c 'git rm --cache $1' -
# show cached diff
dc = diff --cached
@Camwyn
Copy link
Author

Camwyn commented May 28, 2015

Note that ab, mm and svnp are the three parts of https://gist.github.com/Camwyn/c4496d9c064d67bd41f2

@Camwyn
Copy link
Author

Camwyn commented May 19, 2016

I tried using variables for pub but they never worked correctly for me - thus this version of a publish shortcut.
Would be nice if you could use aliases in aliases...hmm...

@Camwyn
Copy link
Author

Camwyn commented Feb 14, 2017

Updated with descriptive comments - also added the tag push to git ab <branchname>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment