Chaining Git commands
Posted 7th July 2020 in Development and Git
Something I like to do to fill the time while waiting for tests to run (and hopefully pass!) on a branch that I’m going to merge to master
is write a chain of Git commands.
Here’s an example. I use GitFlow (GitHub Flow didn’t quite stick) so here’s how I tidy up after a hotfix:
- Jump from my
hotfix
branch back tomaster
, where the fix has been merged to on the remote - Pull the fix down to keep my local
master
in sync - Delete the local hotfix branch, now that the work’s in
master
- Jump to
develop
with a view to merging the fix over there - Merge
master
intodevelop
- Push
develop
to its remote namesake to avoid any potential remote merge conflicts - Fetch the remote repo and prune any dead branches up there
Here’s what the command would look like:
git checkout master && git pull && git branch -d hotfix/fixing-a-thing && git checkout develop && git merge master && git push && git fetch -p
So all you’ve got to do is write &&
between each command and you can get Git to do a whole bunch of things in sequence.
Note: I could make this an Alias in my .gitconfig
file, but doing it longhand that feels better.