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:
- Clean up my fork, see this answer
- 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?
One Solution collect form web for “Github: Clean up fork after pull request”
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
On github, you would fork the
upstream repository. Lets call this one
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
Once you are happy with the changes you have made, you will want to push your changes from the
local repository to the
You can now create a Pull Request on
upstream from the
fix-issue-101 branch on
origin to the
master branch on
You can continue creating branches on
origin while you wait for the Pull Request to be accepted, and hence create additional Pull Requests.
upstream has changes, i.e your Pull Request was accepted, you would pull from
local. You then push
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.