# 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](https://help.github.com/en/articles/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: git@github.com:/b-repository.git Push URL: git@github.com:/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 git@github.com:/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 git@github.com:/a-repository.git (fetch) a git@github.com:/a-repository.git (push) origin git@github.com:/b-repository.git (fetch) origin git@github.com:/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 git@github.com:/b-repository.git ... git push origin master # pushes changes to git@github.com:/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 ```