Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Github: Clean up fork after pull request

I have forked a github repository, made a commit (title Some small changes), submitted a pull request and it got merged into the main repository (commit title Some small changes (#12), where #12 is the pull request number). So far, so good.

Now, when I want to update my fork (git rebase upstream/master, see here), I have this commit twice in my repository. First as Some small changes and then again as Some small changes (#12). If I create a new pull request, the Some small changes commit is again added to the pull request.

There are two ways to work around this issue:

  1. Clean up my fork, see this answer
  2. Merge all commits into one, see this answer

Both cases involve rewriting my history and having to force-push. Is there a better way to keep your fork in sync while committing pull requests?

like image 435
Julian Helfferich Avatar asked Jul 28 '16 16:07

Julian Helfferich


1 Answers

Yes. I would assume there are a few ways to do this but here is what I do.

So you want to contribute to a repository on github, lets call this upstream.

On github, you would fork the upstream repository. Lets call this one origin.

Then on your development machine you would clone origin so you can work on the code. Lets call this one local. When you clone this repository, you very likely already have origin set up as a Remote Repository. You will also need to add the upstream repository as a Remote Repository.

Then when you want to make a change, don't make this change on the master branch. Instead create a new branch for your changes. i.e fix-issue-101

Once you are happy with the changes you have made, you will want to push your changes from the local repository to the origin repository. You can now create a Pull Request on upstream from the fix-issue-101 branch on origin to the master branch on upstream.

You can continue creating branches on local and origin while you wait for the Pull Request to be accepted, and hence create additional Pull Requests.

When master on upstream has changes, i.e your Pull Request was accepted, you would pull from master on upstream to master on local. You then push master on local to master on origin. After doing so, the master branches of all repositories will be back in sync.

I hope I've written this in an understandable manor. If not feel free to ask questions and I'll update accordingly.

like image 143
Vishal Madhvani Avatar answered Nov 02 '22 23:11

Vishal Madhvani