1

I have made a fork from the project manager's master branch. According to my understanding, now the manager's master branch is upstream/master, the one I just forked is origin/master. I have made several changes to origin/master, some of the changes are just adding comments and code for printing intermediate results which serves my own understanding. But there are also changes which are newly written code. I committed all the changes in one single commit. But I want to send a pull request to upstream/master only for the newly created code. I didn't have an easy solution for my goal, as stated in this Stack Overflow question.

Now I want to create another branch called Branch1 at origin, and this branch should be identical to the upstream, then I only commit the newly written code to Branch1, and send a pull request to upstream from this Branch1. Is this approach doable in current github system? If yes, can you please tell me how exactly this can be done.

EDIT

Based on a combination of the following comments, answers and my own searching, I solved the problem. What i did is the following:

  1. git checkout -b Branch1 upstream/master, this will get an identical copy of upstream/master and make it as a new branch named Branch1
  2. git checkout Branch1, and in file config,change the remote for Branch1 to origin
  3. git checkout master somefolder, master should be origin/master at this point.
  4. git commit -m 'message'
  5. git push, somefolder will be pushed to Branch1
Community
  • 1
  • 1
Allanqunzi
  • 3,230
  • 1
  • 26
  • 58

1 Answers1

1

The workflow when working with github is a mix of git commands and actions on github. Lets say your managers repo is at https://github.com/manager/repo and your name is allanqunzi on github.

1) Fork the repo on github so that you have the repo under https://github.com/allenqunzi/repo

2) Clone this repo to your machine with git clone git@github.com:allenqunzi/repo.git

3) the output of git remote -v should show only one remote with the name origin pointing to your repo at git@github.com:allenqunzi/repo.git

4) make your changes and commit them. push them with git push origin master to your repo

5) go to github and open a pull request. it should show up as a new pull request in your manager's repo. it says that you want someone to merge allenqunzi/repo master into manager/repo master.

6) someone accepts the PR and your code is finally into your managers repo.

Optional Info A)

If while you are working something cahnges in manager/repo and you need this locally, you can add the manager repo as a second remote with git remote add upstream git@github.com:manager/repo.git. git remote -v shows now two different remotes. Now you can do git fetch upstream/master and git merge upstream/master to update your local repo, then push it with git push origin master to update your repo on github.

Optional Info B)

You can also add commits in a different branch, push this branch and open a PR from this branch to the master branch of your managers repo.

Optional Info C)

If you just want to add certain files/commits to the managers repo, create a new branch locally. Then cherry-pick all the commits into this branch. Or copy all files you want to change in it, then make a new commit. Push this branch and open a pull request with this branch (see B) for more)

Further readings

Two resources are maybe helpful too (they explain kind of the same but maybe a bit more clear ;))

"Fork a repo" https://help.github.com/articles/fork-a-repo/

"Syncing a fork" https://help.github.com/articles/syncing-a-fork/

ben
  • 1,819
  • 15
  • 25
  • My problem is step 4. I have made changes in one single commit to `origin/master`, among these changes there are some I don't want to pull request, and there are also some I want to pull request. Right now I can not select which specific file to pull request, I can only pull request all the changes I made. – Allanqunzi Jul 29 '15 at 20:12
  • 1
    added Optional Info C. this should help – ben Jul 29 '15 at 22:17