Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GitHub: How to create pull request from forked repository to upstream repo only including some past commits

I forked a template repository (T) on GitHub and did some work in my own repo (X) making use of the template.

Now repo X completely conflicts with repo T because of custom work I pushed to X.

Other than doing custom work with the template, I also did some improvements to the template.

I created a pull request but it contains all my past commits since forking. I want to include only template improvements (just a few commits in the middle of my commit history) in the pull request. How can I achieve this?

like image 743
Raymond Avatar asked Nov 09 '22 13:11

Raymond


1 Answers

You have to separate the template changes (improvement commits, that you want to merge to the upstream repo with a pull-request) from your custom commits.

The better way is to use two different git repositories, but in case of you prefer to maintain only one you have to:

  1. Backup your history, creating a new temp branch git checkout -b tempmaster git checkout master # return to the previous one if master
  2. If you didn't it before, add the original template repository (T) as upstream remote: git remote add upstream https://github.com/...
  3. Fetch all remote changes git fetch --all
  4. Hard reset your current branch to the upstream repository git reset --hard upstream/master # if master
  5. Import your improvements commits ( git cherry-pick ) from the temp branch and fix conflicts.
  6. Once finish, push the new "rebased" branch and create the pull-request
  7. Now from this branch you can create your own custom branch git checkout -b myapp and import yours custom commits in the same way.

Once fixed, when you want to update your forked branch (master) with upstream changes, use rebase: git rebase upstream/master

like image 54
Dario Avatar answered Nov 15 '22 05:11

Dario