If you're not using git's aliases feature (here's a nice, curated list of examples), you're really missing out on a speedier, and safer workflow.
One of my favorites that I've written is git save
, which just takes all of my local changes (and untracked files) and commits them to a new branch.
I use it to create quick "checkpoints" that allow me to safely track my progress with micro-commits, so that I don't accidentally blow away 97 files and an hour of work.
It's really simple to use aliases.
- Use
git config -e --global
to open your global git config file in your editor of choice. (Determined by the$EDITOR
variable) - Add your aliases underneath the appropriate header.
[alias]
save = "!f() { git add -A && git commit --no-verify -am 'SAVEPOINT'; }; f"
This alias looks pretty wild, but is simple once you know what f
is doing here.
We're defining an inline-bash function, and then immediately calling it at the end.
So !f() { ... }; f
is just a construct to define some random bash functionality, and then run it.
The meat inside those brackets, is the real logic:
git add -A
adds all of the changes in the current directory to the staging area, including untracked files.git commit --no-verify -am 'SAVEPOINT'
commits all of those changes to a new commit, with the messageSAVEPOINT
.
The --no-verify
flag is important, because it skips any pre-commit hooks that you might have set up, which is useful in projects that do linting or other checks before committing.
Ideally this is used to create quick-n-dirty commits to keep your work tracked in VCS... You know, so you don't accidentally blow away 97 files and an hour of work.