trex
trex

Reputation: 4037

How to merge latest changes from a base repo to a forked repo

2 years ago I had forked a git repository. After that we made some changes on our side not much but we have changed little things in many files.

Now there are some fixes+features in base git repo from which we had forked. Since now we want to include those changes to our forked one, by keeping our local changes constant.

Is there any way to merge latest repo changes to our forked repo keeping our local changes as it is?

Upvotes: 0

Views: 732

Answers (2)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 521239

In addition to Makoto's answer which describes how to git merge the changes from the base repo branch into your forked branch, you could also consider doing a git rebase. Consider the following diagram:

base branch: A <- B <- C
your branch: A <- D <- E <- F

If you git rebase your branch on the base branch, then your branch would end up looking like this:

your branch: A <- B <- C <- D' <- E' <- F'

The rebase allowed you to pull in all the changes from the base branch, while essentially keeping the same commits you had on your branch intact, and in the same order you had made them over the past two years. I don't know if this is what you had in mind when you said "keeping our local changes as it is" but this might fit the bill.

You will also probably have merge conflicts here as you would with doing a merge, so get ready for some tedious fun.

Upvotes: 1

Makoto
Makoto

Reputation: 106430

If the changes are isolated onto their own branch, then you can simply pull the changes in from the upstream repository.

git pull

Mind you, this is equivalent to a git fetch && git merge operation.

If you want to include these new changes into your specific branch, you'll have to merge them in via git merge. Bear in mind, with changes to a code base from over two years old, you'll likely run into merge conflicts. At that point, you'll want to figure out what's changed from the old API to the new API and determine the best way to move forward.

Upvotes: 1

Related Questions