Some notes about how I work with stacked branches (a.k.a. dependent PR's).
Kindof a pain but it works. This could probably be automated with some clever scripting against github's API.
Create your first PR as per normal:
- (assuming you are currently in the
develop
branch) git checkout -b OTT-217-cake
- edit some files
git add .
git commit -m "OTT-217 Add some cake to the fridge"
git push origin
- go to github.com and make a PR
Now, while waiting for that PR to be approved, if you need to continue making more changes, proceed as per usual except you'll be branching off of your existing branch, rather than branching off of develop
.
- (assuming you are currently in the
OTT-217-cake
branch) git checkout -b OTT-218-more-cake
- edit some files
git add .
git commit -m "OTT-218 Add another cake to the fridge"
git push origin
- go to github.com and make a PR
The key difference is that on github.com you'll change the "base" from develop
to OTT-217-cake
when creating the second PR.
Click the "squash and merge" button on github.com, then "unstack" your second PR:
git checkout develop
git pull
git checkout OTT-218-more-cake
git rebase develop
git push --force
Then go to the second PR in github.com and change the "base" to develop
.
Click the "squash and merge" button on github.com.
Tips:
I don't actually type
git push origin
, because sometimes the upstream isn't set, etc. I instead use this alias:and I simply type
push
(or in this case,push --force
).Also,
git checkout -
will checkout whatever the previous branch was. Handy when frequently branch switching. (This is easy to remember becausecd -
does the same thing for directories).