vfclists
vfclists

Reputation: 20251

Does Github have a way to synchronize your fork with cloned repo?

Does Github offer a way to synchronize a fork of a Github repo with changes in the source repo?

For instance say I fork a repo, and rename the master to upstream which I want to keep synchronized with changes to the source repo, can Github synchronize my upstream with the master of the source repo regularly?

Upvotes: 1

Views: 80

Answers (2)

jherran
jherran

Reputation: 3367

No, github does not provide it. Instead you can achieve it locally.

First, create local repository, add your own remote and retrieve it.

git init
git remote add origin [email protected]:<username>/<repo>.git
git pull origin master

Next step, add a remote branch to your repository that points to the original repo you forked from.

git remote add --track master <repo-name> git://github.com/<username>/<source-repo>.git

Note that master will be the branch you want to track in the forked repo. <repo-name> is up to you. If you want to verify, simply run git remote and you must see <repo-name> and origin as output.

Now, you are ready to get all new changes from original repo.

git fetch <repo-name>

A new branch called <repo-name>/master will be created with latest changes.

Upvotes: 2

Denis Mysenko
Denis Mysenko

Reputation: 6534

Yes, you can synchronise it – it's called merging. You can merge your branch with master branch anytime, but if there are any conflicts (incompatibilities) – you will have to fix them manually.

For example, while in your source folder, assuming that Github is already configured:

git checkout upstream
git merge master

As I already mentioned, if you change something in your branch and master branch changes the same lines of code – automatic merge won't work, you will have to decide manually what version to keep.

Upvotes: -1

Related Questions