Skip to content

Instantly share code, notes, and snippets.

@bravegag
Last active September 21, 2019 09:59
Show Gist options
  • Save bravegag/29513263030493d0194a5576ee845a10 to your computer and use it in GitHub Desktop.
Save bravegag/29513263030493d0194a5576ee845a10 to your computer and use it in GitHub Desktop.
Mirroring and taking upstream updates from an existing repository

Mirroring and taking upstream updates from an existing repository

Definitions

a-repository is the repository we'd like to mirror and b-repository is the mirroring repository. b-repository will mirror the a-repository and take any future updates going into a-repository.

Mirror the repository

Follow the steps in the article Duplicating a repository but change the names as follows: old-repository corresponds to a-repository and new-repository corresponds to b-repository.

Check the remote urls

Check the current remote urls for b-repository:

cd b-repository
git remote show origin

and the output should start with:

* remote origin
  Fetch URL: [email protected]:<username>/b-repository.git
  Push  URL: [email protected]:<username>/b-repository.git

Add a-repository as remote upstream for b-repository

The following connects the b-repository to fetch updates from a-repository as a:

cd b-repository
git remote add a [email protected]:<username>/a-repository.git

Check that the a-repository was added as remote upstream

Doing the following:

git remote show -v

Should now starts with:

a	[email protected]:<username>/a-repository.git (fetch)
a	[email protected]:<username>/a-repository.git (push)
origin	[email protected]:<username>/b-repository.git (fetch)
origin	[email protected]:<username>/b-repository.git (push)

Use your b-repository to fetch and push

Now you may do the usual:

cd b-repository
git pull # pulls from [email protected]:<username>/b-repository.git
...
git push origin master # pushes changes to [email protected]:<username>/b-repository.git

Pull changes from a-repository into the b-repository

Remember that we labelled the a-repository as a:

cd b-repository
git pull a master # can use any other branch than master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment