How to add a local repo and treat it as a remote repo

为君一笑 提交于 2019-11-26 07:53:35

问题


I\'m trying to make a local repo act as a remote with the name bak for another local repo on my PC, using the following:

git remote add /home/sas/dev/apps/smx/repo/bak/ontologybackend/.git bak

which gives this error:

fatal: \'/home/sas/dev/apps/smx/repo/bak/ontologybackend/.git\' is not a valid remote name

I\'m trying to sync two local repos, with one configured as a remote named bak for the other, and then issuing git pull bak.

What is the best way to do it?


Edit:

Sorry, silly me, I\'ve just realized the remote add should be:

git remote add bak /home/sas/dev/apps/smx/repo/bak/ontologybackend/.git

the name of the remote goes before the address.


回答1:


You have your arguments to the remote add command reversed:

git remote add <NAME> <PATH>

So:

git remote add bak /home/sas/dev/apps/smx/repo/bak/ontologybackend/.git

See git remote --help for more information.




回答2:


If your goal is to keep a local copy of the repository for easy backup or for sticking onto an external drive or sharing via cloud storage (Dropbox, etc) you may want to use a bare repository. This allows you to create a copy of the repository without a working directory, optimized for sharing.

For example:

$ git init --bare ~/repos/myproject.git
$ cd /path/to/existing/repo
$ git remote add origin ~/repos/myproject.git
$ git push origin master

Similarly you can clone as if this were a remote repo:

$ git clone ~/repos/myproject.git



回答3:


It appears that your format is incorrect:

If you want to share a locally created repository, or you want to take contributions from someone elses repository - if you want to interact in any way with a new repository, it's generally easiest to add it as a remote. You do that by running git remote add [alias] [url]. That adds [url] under a local remote named [alias].

#example
$ git remote
$ git remote add github git@github.com:schacon/hw.git
$ git remote -v

http://gitref.org/remotes/#remote



来源:https://stackoverflow.com/questions/10603671/how-to-add-a-local-repo-and-treat-it-as-a-remote-repo

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!