1

I've read the fine manual, and read through quite a few questions here, but I'm still not certain how to handle submitting patches via pull requests properly.

I'm using GitHub for Windows (but I'm fine with using the command line if needed).

Here's what I'm doing, and where I'm getting confused:

  1. Forked the original GitHub project to create my own.
  2. Made change A, which I want the original project to include.
  3. Sent a pull request for A, which they accepted, so it's now part of the original project.
  4. Made change B, which is of no use to them, so I don't want them to include it in their version.
  5. Made change C, which I do want them to use.
  6. More commits, some of which are of value to them, some of which are not.

What is the proper order of forking/branching/pull request/merging to:

  1. Make sure I have a version with ALL of my changes.
  2. Make sure I can share certain changes with the upstream project.
  3. Once I make change B in my master branch, any new branches would include it, so how do I either send just the relevant changes for C? Or do I need to somehow create a new branch based on what upstream still has in their copy?

I mostly just want to make sure I'm not causing the upstream devs extra work having to go back and cherry-pick certain changes. The easier I make it for them to fix the bugs the better, then everyone is happy!

2
  • 1
    Have you thought about just keeping a branch for your work and keeping that up to date with their master?
    – Leo Correa
    Commented Sep 2, 2013 at 0:54
  • 1
    I would recommend doing your work in a topical branch rather than on master. Then you just create the PR from your branch. Commented Sep 2, 2013 at 1:20

2 Answers 2

1

The usual workflow for forked projects is to make your own branch (or branches) based off of an upstream branch (often this will be upstream/master), and do all of your work in those. Each branch usually encapsulates a single feature. You would send pull-requests for features you want to contribute.

So, for your example:

Made change A, which I want the original project to include.

You would usually want to make a feature or bug-fix branch for change A and submit it as a pull request on GitHub, like so:

# Make a branch based off of upstream/master
git checkout -b branch-A upstream/master

# Make some changes, then commit them
git add .
git commit

# Push the branch to your fork, then go to GitHub and submit the pull-request
git push origin head

Made change B, which is of no use to them, so I don't want them to include it in their version.

If you don't want the project owners to have this change, keep it isolated to its own branch, and don't make a pull-request for it. Note that you can still backup the branch to your own remote fork, if you want to:

# Make a branch based off of upstream/master
git checkout -b branch-B upstream/master

# Make some changes, then commit them
git add .
git commit

# Push the branch to your fork
git push origin head

Made change C, which I do want them to use.

Make another branch for C, just like you did for A:

# Make a branch based off of upstream/master
git checkout -b branch-C upstream/master

# Make some changes, then commit them
git add .
git commit

# Push the branch to your fork, then go to GitHub and submit the pull-request
git push origin head
4
  • So for any changes I want to share, I always make a new branch based on upstream/master? And to make my own all-inclusive version, I can merge branches A, B and C into my master branch?
    – Grant
    Commented Sep 2, 2013 at 1:27
  • You usually don't want to be making any changes to the master branch at all, only fetching updates for it (from the upstream repo) and making branches from it. But yes, the typical GitHub workflow is to make a branch for changes that you want to share...but also for changes that you want to keep for yourself!
    – user456814
    Commented Sep 2, 2013 at 1:33
  • So I end up with master (which I occasionally update to match upstream), a branch for each unrelated change I make, and a branch that I merge all my changes which haven't been included upstream into (for my own use)?
    – Grant
    Commented Sep 2, 2013 at 1:58
  • You can do it that way, yes, and it seems like an appropriate approach.
    – user456814
    Commented Sep 2, 2013 at 2:13
0

Update Match 2015:

See "Create Pull Requests in GitHub for Windows"

Just like our Mac client, you can now use GitHub for Windows to submit pull requests to GitHub or GitHub Enterprise, right from your desktop.

We didn't forget forks, either! If you fork a repository and then want to contribute changes to the upstream repository, GitHub for Windows will keep track of upstream branches. This means less hassle when you're ready to contribute your changes back.


(August 2013) Note that, with the GitHub clients (GitHub for Windows or GitHub for Mac), it is easy to:

https://f.cloud.github.com/assets/432536/943708/46a2f12e-0251-11e3-8c46-b1b6636f23d5.png

https://f.cloud.github.com/assets/432536/1160834/a3bbd0be-1fdf-11e3-90aa-13ee15c6c2d8.png

Clicking it will:

  • open GitHub for Mac or GitHub for Windows,
  • clone the repository (if you don't have it),
  • automatically switch to the branch containing the changes, and
  • finally open the file for editing in its default application.

So if you don't like command-lines... you have another option.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.