Asara
Asara

Reputation: 3384

How to sync a patched or rebased GIT repository?

The owner of a repo that I forked regularly rebases and patches his commits (and push requests) rather than just merging or adding them. When I want to sync with his repo, git/Github wants to merge everything since the patched commit, although only this patch should be synced.

Ok I think I must specify my problem. Yes, its no problem to PULL the changes from upstream into my local repo, because I can rebase here as well. But when I want to sync my fork on GitHub (origin), I dont know how to rebase the commit history there as well. When I want to push my rebased history, git tells me that I have to pull from origin first, because the base has changed (becaus I rebased my local copy of my Github fork).

So the question is more likely, how to sync my Github fork with the original rebased repo?

Upvotes: 1

Views: 286

Answers (2)

nimatt
nimatt

Reputation: 519

If the owner has rewritten commits using rebase och ammend I would say that you have to use cherry-pick or interactive rebase.

Cherry pick

  1. Checkout the new branch you want to sync to
  2. Cherry pick each of your own commits

Interactive rebase

  1. Start an interactive rebase
  2. Set all commits to which you're not the author to skip

Edit, updated question

To be able to push your local branch to your own repo you have to use --force to overwrite the old commits that have changed. Like so

git push origin master:master --force

After a rebase or an amend the changed commits will be completely different (the commit time will change even if you don't change any content and with that you get a completely new commit hash). You therefore need to "throw away" the old commits that are in you github repo.

Upvotes: 1

Vy Do
Vy Do

Reputation: 52606

You can't rebase 2 repositories: your forked repository vs. upstream repository. You only apply merge.

Reference about update a fork: https://help.github.com/articles/syncing-a-fork/

Upvotes: 1

Related Questions