在远程服务器上创建本地 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 04:59:26  来源:igfitidea点击:

Creating a copy of local git repository on a remote server

git

提问by Rob

I have cloned a project from a server using git cloneand 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 trueand delete everything but the .gitfolder 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 --bareand simply push my local one to it but as I originally cloned my local copy from another server, the originseems to be blocking me from doing this.

我希望我可以使用创建新的远程存储库git init --bare并将我的本地存储库推送到它,但由于我最初从另一台服务器克隆了我的本地副本,这origin似乎阻止了我这样做。

回答by Roman Cheplyaka

  1. Create a fresh bare repository on the server:
    git init --bare newrepo.git
  2. Add it as a remote in your local repo:
    git remote add newrepo git://[email protected]/newrepo.git
  3. git push newrepo masterto push a particular branch, or
    git push --all newrepoto push all branches
  1. 在服务器上创建一个全新的裸仓库:
    git init --bare newrepo.git
  2. 将其添加为本地存储库中的远程:
    git remote add newrepo git://[email protected]/newrepo.git
  3. git push newrepo master推送特定分支,或
    git push --all newrepo推送所有分支

回答by gahooa

Another way is (as you wished):

另一种方法是(如您所愿):

git clone --bare /path/to/repo newrepo.git