Skip to content

Instantly share code, notes, and snippets.

@theiwaz
Last active May 15, 2020 05:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theiwaz/b793ebac44ef0dee3de67d69c7aa0ba6 to your computer and use it in GitHub Desktop.
Save theiwaz/b793ebac44ef0dee3de67d69c7aa0ba6 to your computer and use it in GitHub Desktop.

Multiple remotes

Setup remotes

  1. Create fresh git repo somewhere without initialising it.
  2. In your repo push to the new remote

git push https://git-codecommit.us-east-2.amazonaws.comMyClonedRepository --all

Refs:
https://docs.aws.amazon.com/codecommit/latest/userguide/how-to-migrate-repository-existing.html
https://jigarius.com/blog/multiple-git-remote-repositories

Add extra remote and create and 'One remote to rule them all'

Add extra remote

git remote add upstream [extra remote url]

Here 'upstream' is the name of the remote pointing to [extra remote url]

See how the tracking is setup for your branches

git branch -vv

Make sure the right branches are pointing to the right remote. Branches can only have one remote to push to. If not correct by setting the right remote push remote.

git branch -u origin/BRANCH

This command sets the 'upstream' (-u) for the current branch to the branch called 'BRANCH' on the remote called 'origin'.

One to rule them all

  1. Say, we call it “all”: git remote add all [extra remote url].
  2. Register 1st push URL: git remote set-url --add --push all [extra remote url]
  3. Register 2nd push URL: git remote set-url --add --push all [primary remote].

You cannot pull from multiple remotes, but you can fetch updates from multiple remotes with git fetch --all.

Refs:
https://jigarius.com/blog/multiple-git-remote-repositories
https://www.youtube.com/watch?v=PJN2zVG338w&feature=youtu.be

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment