Github Fork & Pull: My PR was accepted, how to keep working on my fork?

Recently I started collaborating to an open source project.

Using the fork and pull method I sent my first PR and it has been approved.

How can I work on the next issue using the same forked repository?

Since my PR has been merged my current master branch is behind the original repository.

I managed to think about two solutions:

  1. merge the PR branch to my master branch and create a new branch based on master to work on the new issue.
  2. create an "upstream" remote and execute a pull on local master branch.

Which one is better? Is there another option?

Upvotes: 2

Views: 79

Answers (1)

larsks
larsks

Reputation: 312183

Don't work on master in your local repository. A good workflow looks like this:

  • Fork the upstream repository on github.

  • Clone the upstream repository locally:

    git clone [email protected]:/someproject/somerepo.git
    
  • Add your fork as an additional remote:

    cd somerepo
    git remote add mine [email protected]:/me/somerepo.git
    
  • Make sure your local repository is up-to-date with respect to the upstream repository. Obviously this is already the case if you just cloned it, but otherwise:

    git checkout master
    git pull
    

    Note that this will pull from the upstream master branch, not your fork. This is what you want.

  • Create a new branch off master for your work:

    git checkout -b my-spiffy-feature
    
  • Do you work, and push the branch to your fork:

    git push -u mine my-spiffy-feature
    
  • Submit a pull request against the upstream master.

At this point, you can start doing other work. You can create another new branch off master:

    git checkout -b another-feature master

Or you can base it on your previous work, if necessary:

    git checkout -b another-feature my-spiffy-feature

When your previous pull request is accepted upstream, update your local master branch:

    git checkout master
    git pull

And then rebase any existing work off the updated master branch:

    git checkout another-feature
    git rebase master

With this workflow, master always tracks upstream, and your work is always done on isolated branches, which makes it easy to handle multiple pull requests.

Upvotes: 3

Related Questions