Updating a local fork without pushing merge commits?
Asked Answered
M

1

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!

Mervinmerwin answered 2/6, 2014 at 14:37 Comment(0)
P
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.

Pyrophoric answered 2/6, 2014 at 14:48 Comment(5)
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?Mervinmerwin
@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.Pyrophoric
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?Mervinmerwin
@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.Pyrophoric
@SyntacticFructose for more on pull requests: https://mcmap.net/q/99795/-how-to-do-a-github-pull-requestPyrophoric

© 2022 - 2024 — McMap. All rights reserved.