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.

  • How do you manage your forked reusable apps on django with git
  • Updating multiple branches of a forked repository on Github
  • Forking on Google Code (or any other SVN hosting)
  • git merge and got this error “does not point to a commit”
  • How to choose the right branch/fork to use by looking on the github's network graph?
  • Git, Create a clone/fork but keeping my projects “origin-parts” updated from the source?
  • 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?

  • How to keep update from several Git repositories as one application project?
  • Removing unwanted files from history including all refs with filter-branch
  • Git Mergetool: “No files need merging”
  • git-clone fatal, permission denied
  • Git: Ignore files for public repository, but not for private
  • git svn rebase problem on windows
  • 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 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.

    Git Baby is a git and github fan, let's start git clone.