Skip to content

Instantly share code, notes, and snippets.

@theluk
Created July 15, 2021 09:17
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 theluk/ace14cf57af7c692bd697c66b29ee0c9 to your computer and use it in GitHub Desktop.
Save theluk/ace14cf57af7c692bd697c66b29ee0c9 to your computer and use it in GitHub Desktop.
#!/bin/bash
trap "exit 1" ERR
isPush=false
if [[ "$1" == "--push" ]]
then
isPush=true
shift
else
isPush=false
fi
while [ $# -gt 1 ]; do
git checkout $2
git merge $1
[ "$isPush" = "true" ] && git push
shift
done
@theluk
Copy link
Author

theluk commented Jul 15, 2021

if you have already some PRs waiting for review and they build all on top of each other, this utility comes in handy.

git-merge-consecutive branch-a branch-b branch-c

this will do

$ git checkout branch-b
$ git merge branch-a
$ git checkout branch-c
$ git merge branch-b

Heads up: Usually it is not the best idea to make branches dependent on each other while they are in review. Why? It can happen that one PR gets rejected so badly, that you would need to rewrite it completely. So there is a risk, that all consecutive branches / pull requests depend on something this will go into trash. But I am not your mother, and because you know what you are doing, you know when you can use this utility

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