Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merging upstream git changes with pending pull requests

Tags:

git

github

I keep running into problems with git in a common workflow on GitHub.

  1. I fork a repo
  2. I commit some changes
  3. I make a pull request to upstream repo
  4. Twiddle thumbs while upstream developer sits on my pull request.
  5. Upstream developer makes changes to their repo
  6. They look at your pull request, but because of changes in their tree it will no longer apply cleanly, so they ask you to update your pull request.
  7. I fetch & merge changes from upstream into my repo, resolve conflicts, commit changes
  8. I rebase commits in my pull request to make it neat and tidy.

This is where the problem arises: my pull request now contains all the changes that occurred between steps 2 and 7, including the upstream developer's own changes. In a recent example this expanded a 10-line pull request to over 12,000 lines.

How should I reapply my original commits onto a later version of the upstream repo without their changes getting into my pull request?

like image 982
Synchro Avatar asked Nov 26 '12 08:11

Synchro


People also ask

How do I merge Pull requests?

Adding a pull request to a merge queueOn GitHub.com, navigate to the main page of the repository. Under your repository name, click Pull requests. In the "Pull Requests" list, click the pull request you would like to add to a merge queue. Click Merge when ready to add the pull request to the merge queue.


1 Answers

Change this

7) I fetch & merge changes from upstream into my repo, resolve conflicts, commit changes.

8) I rebase commits in my pull request to make it neat and tidy.

to

I rebase my repo onto upstream, making it neat and tidy.

We'll assume you forked the feature branch from upstream/master, and we'll use a temporary branch to be safe. If things go wrong, just delete the feature-rebase branch and start over.

git checkout feature
git checkout -b feature-rebase
git rebase -i upstream/master

This will replay your commits on top of upstream/master, as if you had forked right now. Once everything looks good, replace the old feature branch with the rebased version.

git branch -m feature feature-old
git branch -m feature-rebase feature
git branch -d feature-old
git checkout feature
git push -f origin feature
like image 190
piedar Avatar answered Sep 17 '22 13:09

piedar