Skip to content

Instantly share code, notes, and snippets.

@f000
Last active November 4, 2015 11:15
Show Gist options
  • Save f000/d3fef983bfa6aef8c21f to your computer and use it in GitHub Desktop.
Save f000/d3fef983bfa6aef8c21f to your computer and use it in GitHub Desktop.
Aliases for ~/.gitconfig
[alias]
# Edit global config in your favourite editor
ec = config --global -e
# Common shortcuts
co = checkout
c = commit
st = status
br = branch
# Nice log output
hist = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short
# Instead of the content, show the object type identified by <object>
type = cat-file -t
# Pretty-print the contents of <object> based on its type
dump = cat-file -p
# http://haacked.com/archive/2014/07/28/github-flow-aliases/
# Ensure working directory is up to date with the origin
up = !git pull --rebase --prune $@ && git submodule update --init --recursive
# Start new branch
cob = checkout -b
# Commit everything
aa = !git add -A && git commit -m
# Temporary save (use this instead of git stash because stash is global for all branches)
# Add all changes including untracked files and create a commit
save = !git add -A && git commit -m 'SAVEPOINT'
# or commit tracked changes only
wip = commit -am "WIP"
# then reset the previous commit, but keep all the changes from that commit in the working directory
undo = reset HEAD~1 --mixed
# or amend with new changes
amend = commit -a --amend
# Commit everything in working directory and then do a hard reset to remove that commit
wipe = !git add -A && git commit -qm 'WIPE SAVEPOINT' && git reset HEAD~1 --hard
# Git flow - completing the pull request (delete merged branch via GitHub UI first)
# Deletes all branches already merged into master (used in bdone)
bclean = "!f() { git branch --merged ${1-master} | grep -v " ${1-master}$" | xargs -n 1 git branch -d; }; f"
# Switches to master, runs git up to bring master up to speed with the origin and deletes all branches already merged into master using git bclean
bdone = "!f() { git checkout ${1-master} && git up && git bclean ${1-master}; }; f"
# Branch publishing
# Get the current branch name (not so useful in itself, but used in other aliases)
branch-name = "!git rev-parse --abbrev-ref HEAD"
# Push the current branch to the remote "origin", and set it to track the upstream branch
publish = "!git push -u origin $(git branch-name)"
# Delete the remote version of the current branch
unpublish = "!git push origin :$(git branch-name)"
# Git Assume
# Mark a file as "assume unchanged", which means that Git will treat it as though there are no changes to it even if there are
assume = update-index --assume-unchanged
# Reverse the above
unassume = update-index --no-assume-unchanged
# Show the files that are currently assume-unchanged
assumed = "!git ls-files -v | grep ^h | cut -c 3-"
# Stage automation
# Merge current branch with stage (local and remote stage branch must be present) and push it
pubstage = !git checkout stage && git merge @{-1} && git push && git checkout @{-1}
# Recreate local and remote stage branch from master (old local and remote stage branch must be present) and push
restage = !git checkout master && git up && git push origin :stage && git branch -D stage && git checkout -b stage && git publish && git checkout master
# Which commits are in current branch but not in master brach?
notinmaster = "!git log --oneline --no-merges ^master $(git branch-name)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment