Skip to content

Instantly share code, notes, and snippets.

@pepasflo
Last active May 8, 2019 20:23
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 pepasflo/b1c849002951a644588c019f45a0be01 to your computer and use it in GitHub Desktop.
Save pepasflo/b1c849002951a644588c019f45a0be01 to your computer and use it in GitHub Desktop.

Stacked-PR workflow

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.

Creating the first PR

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

Creating the second 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.

Merging the first 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.

Merging the second PR

Click the "squash and merge" button on github.com.

@pepasflo
Copy link
Author

pepasflo commented May 8, 2019

Tips:

I don't actually type git push origin, because sometimes the upstream isn't set, etc. I instead use this alias:

alias push='git push --set-upstream origin $( git symbolic-ref --short HEAD )'

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 because cd - does the same thing for directories).

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