1

There have been many questions on SOF like these:

  1. doing clean git pull-request to upstream

  2. How do you attach a new pull request to an existing issue on github?

but my problem seems a little different and I couldn't get out of it.
Here's what I did:

  1. I saw that master protected to make any pushes on that
  2. so I made a new branch git checkout -b module1
    wrote something
    git add --all
    git commit -m "____"
    git push origin module1
    raise a pull request
  3. I made another branch git checkout -b module2
    wrote something
    git add --all
    git commit -m "____"
    git push origin module2
    raise a pull request

Now second pull request went with commits of previous module also. TO rectify this I tried:
- after pushing in last step to branch
- I went to master git checkout master then
- git merge module2
Now if I raise a Pull Request it is still showing commits of module1 in Pull Request.

What can I do to fix this and take care with future branches?

Community
  • 1
  • 1
paul
  • 3,639
  • 13
  • 53
  • 106
  • You didn't create module2 based on master above, did you? git checkout -b module2 origin/master would have been correct, no? – Martin G Nov 20 '14 at 10:01
  • I was checked out on master when I created **module2**, does this it is based on master? – paul Nov 20 '14 at 10:04
  • While annoying, I would simply throw away module2, then start again (checking out from master) and force-push to `origin module2`; I hope this was a relatively small PR. And while there may be a single command to do this (keep changes introduced in module2, discard changes in module1), you may also attempt something with `git cherry-pick`. –  Nov 20 '14 at 10:39

1 Answers1

1

You were wrong on step 3, here you need to checkout from module1 branch and goto master branch.
For more clearer description, which you can try on any bitbucket/github.com test repo, you can follow below steps to start from beginning or you can ignore steps which already done and check in your bitbucket/github.com account.

  1. git init (if you see that your directory is not a git repo)
  2. git remote -v (to check branches that you are already fetch or push/pull)
  3. if you see nothing
  4. git remote add origin
  5. git remote add master
  6. do your stuff, lets say stuff1 (here your answer starts, if you have success on above steps)
  7. git checkout -b stuff1 (important step, I created a new branch "stuff1" when I was on master)
  8. git add --all
  9. git commit -m "Stuff1 module is completed, please review and merge"
  10. git push origin stuff1 (important step, you are not pushing to master but stuff1)
  11. git checkout master (important step, you have to go back to master, if you want to repeat steps for stuff2)
  12. go to you bitbucket or github.com login, click "create pull request" you'll branch "stuff1" is created on the other side choose "master" give notes and hit "create pull request" button
  13. Done. Repeat if you want to do more commits in other branches.
paul
  • 3,639
  • 13
  • 53
  • 106