Skip to content

Instantly share code, notes, and snippets.

@christhekeele
Last active February 22, 2018 09:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christhekeele/958f85b6c1daef9e897b70fddf770e7e to your computer and use it in GitHub Desktop.
Save christhekeele/958f85b6c1daef9e897b70fddf770e7e to your computer and use it in GitHub Desktop.
Some git aliases

git chunk

git config --global alias.chunk 'add -p'

Usage: starts an interactive chunk-by-chunk staging session, similar to git rebase -i. Handy for picking apart a full index to make a nicer narrative of small commits.

git current

git config --global alias.current 'rev-parse --abbrev-ref HEAD'

Usage: mostly for reliably interpolating your current branch name into other scripts.

git discard <paths>...

git config --global alias.discard 'checkout --force --'

Usage: discard changes in working directory.

git distance

git config --global alias.distance '!distance(){ git diff ${1:-master}...HEAD --shortstat; }; echo $(distance) since last common commit to ${1:-master}'

Usage: shows you how far you've come since you last diverged from another branch/ref (master by default).

git golf

git config --global alias.golf 'git diff --shortstat'

Usage: less code is better than more code.

git last

git config --global alias.last '!last(){ git diff HEAD~1 HEAD && git log -n1; }; last'

Usage: shows the changes and message of the last commit.

git latest

git config --global alias.latest 'log -n5'

Usage: shows the messages of the last 5 commits.

git oops [<options>] [--] <paths/globs>...

git config --global alias.oops 'commit --amend --no-edit'

Usage: apply changes in index to last commit. Use -a to use entire working tree (except for new files), specify files in particular, or use git add before running as normal.

git rollback <number>

git config --global alias.rollback '!rollback(){ cd ${GIT_PREFIX:-.} && git reset HEAD~${1:-1} --soft; }; rollback'

Usage: unwinds the given number of commits (1 by default) into your index. Destroys commit messages but never any changes.

git unstage [--hard] [--] <paths/globs>...

git config --global alias.unstage 'reset HEAD'

Usage: removes changes from the index. Specify --hard to erase them entirely.

@christhekeele
Copy link
Author

git discard and git unstage in particular are verbatim those two commands you can never remember and have to run git status every time to be reminded of.

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