简体   繁体   中英

Is there a Git equivalent of Hg schemes?

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.

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM