7

I seem to be having some issues with merge commits crowding my pull requests that I don't mean to be pushed. Currently I have a local fork with an upstream set to the base repository, and I update my repository like so:

git fetch upstream
git merge upstream/n3960  

where n3960 is my branch I am working on, the problem is when I push commits to my fork, I get all of these Merge remote-tracking branch 'upstream/master' into n3960 commits from when I updated my branch whenever another member pushes to the base repo, how can I avoid having all of these merge commits in my pull requests?

An example: my recent pull request is crowded with these Merge remote-tracking branch 'upstream/master' into n3960 commits, I want to try and avoid having these overcrowd my actual commits!

Syntactic Fructose
  • 18,936
  • 23
  • 91
  • 177

1 Answers1

13

You don't have to merge.

You can:

# rebase n3690 on top of upstream/master
git checkout n3690
git rebase upstream/master

# then
git push -f 

By forcing the push, that will update automatically your current Pull Request.

And the rebase avoids all those merge commits.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    I just had someone from my IRC channel answer as well, he told me to use `git pull --rebase` , is this answer similar to that? – Syntactic Fructose Jun 02 '14 at 14:54
  • @SyntacticFructose not exactly, as you aren't pulling from `origin`, but from `upstream`, and you aren't pulling `n3690`, but `master`. My method is more tailored to your specific situation. – VonC Jun 02 '14 at 14:56
  • I see, so if I used your method I would always use `git push -f` from now on in order to push my **actual** commits? – Syntactic Fructose Jun 02 '14 at 14:59
  • @SyntacticFructose even with `pull --rebase`, you would ave to force the push: a rebase (however you are doing it) will change the history. But that is ok, since it is your branch, and since the PR (Pull Request) will take the new history into account automatically. – VonC Jun 02 '14 at 15:01
  • 1
    @SyntacticFructose for more on pull requests: http://stackoverflow.com/a/14681796/6309 – VonC Jun 02 '14 at 15:04