3

Say, from my original master, I made certain change to it and committed the change at time t1 I then pushed this to github (calling it branchA). Then I made some other change and committed it at time t2. I don't want to push this to branchA, but I want to push it to another branch called branchB.

Is it possible to list branchA as the prerequisite for branchB so that when I do a pull request, the diff in branchB does NOT include the changes committed prio to t1, in other words, the diff in branchB should only show the diff between branchA and branchB?

Bazaar/Launchpad offers this option, but I haven't been able to find the similar feature in Github. (I'm new to git, so maybe this isn't something they do in Github?)

user1508893
  • 9,223
  • 14
  • 45
  • 57

1 Answers1

1

That means you have:

Local Repo                  Upstream (GitHub Repo)

 .--.--o--x--y branchA   <====> o--o--x branchA
(master)

But you want:

.--.--o--x branchA      <====> o--o--x branchA
(mast) \
        y branchB        => you can push now

That means you need first to rebase onto o what comes after x (t1) in order to build branchB locally, before pushing it to your fork.

git checkout branchA                
git branch branchB                  # creates branchB where branchA currently is
git reset --hard origin/branchA     # reset branchA to x
git rebase --onto master x branchB  
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • To to clarify, if I do this, when my `branchA` gets merged to `master`, the diff on `branchB` and `master` would now be the same as the diff that's been shown there in `branchB` ? – user1508893 Feb 18 '13 at 22:45
  • @user1508893 yes: you are rebasing that diff to master in order to isolate it in its own branch. – VonC Feb 19 '13 at 04:44
  • Thank you, that makes sense now. (Is this something that you know because you have experience with `git` or is there some documentations on this kind of stuff?) – user1508893 Feb 20 '13 at 02:52
  • @user1508893 I do have quite a bot of experience with git (http://stackoverflow.com/tags/git/topusers), and have used `git rebase --onto` as well (http://stackoverflow.com/a/14504917/6309, http://stackoverflow.com/a/9192637/6309, http://stackoverflow.com/a/13400050/6309, http://stackoverflow.com/a/2369516/6309) – VonC Feb 20 '13 at 06:18