在远程服务器上创建本地 git 存储库的副本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4820039/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Creating a copy of local git repository on a remote server
提问by Rob
I have cloned a project from a server using git clone
and I now want to copy it (all branches) to another server so other people can start using it. I guess I could simply copy the entire repository manually and then issue git config --bool core.bare true
and delete everything but the .git
folder but I don't think that qualifies as a 'bare' repository and I'm worried it might give me problems.
我已经从服务器克隆了一个项目,git clone
现在我想将它(所有分支)复制到另一台服务器,以便其他人可以开始使用它。我想我可以简单地手动复制整个存储库,然后发布git config --bool core.bare true
和删除除.git
文件夹之外的所有内容,但我认为这不符合“裸”存储库的条件,我担心它可能会给我带来问题。
I was hoping I could create the new remote repository using git init --bare
and simply push my local one to it but as I originally cloned my local copy from another server, the origin
seems to be blocking me from doing this.
我希望我可以使用创建新的远程存储库git init --bare
并将我的本地存储库推送到它,但由于我最初从另一台服务器克隆了我的本地副本,这origin
似乎阻止了我这样做。
回答by Roman Cheplyaka
- Create a fresh bare repository on the server:
git init --bare newrepo.git
- Add it as a remote in your local repo:
git remote add newrepo git://[email protected]/newrepo.git
git push newrepo master
to push a particular branch, orgit push --all newrepo
to push all branches
- 在服务器上创建一个全新的裸仓库:
git init --bare newrepo.git
- 将其添加为本地存储库中的远程:
git remote add newrepo git://[email protected]/newrepo.git
git push newrepo master
推送特定分支,或git push --all newrepo
推送所有分支
回答by gahooa
Another way is (as you wished):
另一种方法是(如您所愿):
git clone --bare /path/to/repo newrepo.git