0

Mercurial (Hg) has an extension called schemes which is very useful when you're working with a server that hosts all of your repositories and you want to point them at a different server or local directory when you're offline.

Does Git have an equivalent?

I'm interested in this for use with Git submodules. Ideally, I would like to cache all of the repositories on my disk and point a different machine's frech clone to my local repos.

nonsensickle
  • 4,438
  • 2
  • 34
  • 61
  • 1
    The `schemes` extension adds an indirection step. You can get the same effect in Git using `insteadOf`, but it seems that submodules may bypass the normal `insteadOf` handling (I have not tested this myself, I am saying this because someone else had a question about why it wasn't working). – torek Jul 07 '17 at 15:06

1 Answers1

2

You would simply add a new remote to your repo.
git remote add <new_remote_name> <path_or_url>

Since your branches are usually set up to track origin, you'll need to specify the branch you want to pull/push from manually:
git pull <new_remote_name> <remote_branch>
git push <new_remote_name> <local_branch>:<remote_branch>

If you want to make things more permanent, you can either replace the url/path of origin:
git remote set-url origin <path_or_url>

or change the remote branch your local branch is tracking:
git branch -u <new_remote_name>/<remote_branch> <local_branch>

Check this answer for more details on how to push and pull to from multiple remotes simultaneously.
git remote set-url origin --add <path_or_url>
git remote set-url origin --add <another_path_or_url>

rafasc
  • 106
  • 2
  • 7