Git is great, but creating some git aliases is a great way to make your usages even more efficient.
To add any of these you can either copy and paste into the [alias]
section of your .gitconfig
file or run git config --global alias.NAME 'COMMAND'
replacing NAME
with the alias to use, and COMMAND
with what to run.
So without further ado, here are the ones I have created and use on a very regular basis.
Constant usage
git s
- an alias forgit status
. Have to save those 5 keypresses!s = status
git cm "some commit message"
- shorthand for commit with a messagecm = commit -m
git dc
- diff files staged for commitdc = diff --cached
git scrub
- deletes everything not tracked by git (git clean -dxf
) except thepackages
andnode_modules
directoriesscrub = clean -dxf --exclude=packages --exclude=node_modules
Context switching, rebasing on dirty HEAD
I rebase my changes onto the current branches often, but rebasing requires a clean repository to work on. The following two aliases are used something like this: git save && git pull --rebase && git undo
git save
- adds and commits everything in the repository, with the commit messageSAVEPOINT
save = !git add -A && git commit -m 'SAVEPOINT'
git undo
- undoes the last commit, leaving everything as it was before committing. Mostly used to undo agit save
callundo = reset HEAD~1 --mixed
I also use these if I need to save my work to work on a bug fix on a different branch.
What have I done?
Often I want commits I have pending, either to the local master, or a remote tracking branch. These both give an output like this:
git pending
- shows the commits on the current branch compared to theorigin/master
branchpending = log origin/master..HEAD --pretty=oneline --abbrev-commit --format='%Cgreen%cr:%Creset %C(auto)%h%Creset %s'
git pendingup
- shows the commits on the current branch compared to its tracking branchpendingup = "!git log origin/\"$(git rev-parse --abbrev-ref HEAD)\"..HEAD --pretty=oneline --abbrev-commit --format='%Cgreen%cr:%Creset %C(auto)%h%Creset %s'"
More?
I have some others not documented here, but are in my config repo on Github.