Skip to main content

Chaining Git commands

Posted 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:

  1. Jump from my hotfix branch back to master, where the fix has been merged to on the remote
  2. Pull the fix down to keep my local master in sync
  3. Delete the local hotfix branch, now that the work’s in master
  4. Jump to develop with a view to merging the fix over there
  5. Merge master into develop
  6. Push develop to its remote namesake to avoid any potential remote merge conflicts
  7. 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.

Accessibility in your inbox

I send an accessibility-centric newsletter on the last day of every month, containing:

  • A roundup of the articles I’ve posted
  • A hot pick from my archives
  • Some interesting posts from around the web

I don’t collect any data on when, where or if people open the emails I send them. Your email will only be used to send you newsletters and will never be passed on. You can unsubscribe at any time.

More posts

Here are a couple more posts for you to enjoy. If that’s not enough, have a look at the full list.

  1. Avatars and alt text

    I really enjoyed Nicolas Steenhout’s recent article on Alt text for avatars or user photos. But there is a context where I would break his rule…

  2. Upgrading from iPhone 13 mini to 16 Pro

    I get a new phone every 3-ish years, give mine to my wife, and now she gives hers to our daughter. I got a 16 Pro this year! Here’s the skinny.