Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I git pull --rebase but taking all remote changes?

Tags:

git

I did git fetch and then git pull --rebase. It is trying to merge changes from the remote branch to my local branch. And there are some merge conflicts. So I did a git reset --hard.

My question is it is possible for me to ask git pull to take the remote change whenever there is a conflict?

like image 614
michael Avatar asked Aug 09 '10 08:08

michael


People also ask

Does git rebase change remote?

No, locally rebasing doesn't change the remote.

Do you need to git pull before rebase?

It is best practice to always rebase your local commits when you pull before pushing them. As nobody knows your commits yet, nobody will be confused when they are rebased but the additional commit of a merge would be unnecessarily confusing.

How does git pull rebase work?

Git pull rebase is a method of combining your local unpublished changes with the latest published changes on your remote. Let's say you have a local copy of your project's main branch with unpublished changes, and that branch is one commit behind the origin/main branch.

Can you git pull with unstaged changes?

Cannot pull with rebase: You have unstaged changes. Please commit or stash them. Git stash command is kind of commit stored changes to temporary space and clean working copy. Then your working copy will be reverted to HEAD.It is a good place to store uncommitted changes.


1 Answers

I think what you want is this:

git pull --rebase -s recursive -X ours 

But it doesn't work (I'm using 1.7.0.4), even though the manpage says it should. I'm guessing this is due to the issue mentioned here.

Instead, you could use:

git pull -s recursive -X theirs 

It works as expected, but you'll get a merge instead of a rebase.

Also - note 'ours', rather than 'theirs' when using --rebase. From the git-rebase manpage:

[CLIP]... a rebase merge works by replaying each commit from the working branch on top of the upstream branch. Because of this, when a merge conflict happens, the side reported as ours is the so-far rebased series, starting with upstream, and theirs is the working branch. In other words, the sides are swapped. ...[CLIP]

like image 93
Jeff Avatar answered Sep 25 '22 12:09

Jeff