如何从初始git存储库开始创建共享git存储库

时间:2015-12-30 22:49:41

标签: git repository

我目前有一个带有git存储库的项目。我想在另一个位置创建一个共享存储库。我曾经想过我应该采取的方法是首先创建一个裸git存储库,然后将我现有的存储库克隆到它,但这不起作用:

me@computer> git init --bare shared.git  #Create shared repository in new location
me@computer> git clone .git /path/to/shared/repository/shared.git #From dir with existing repository, try to create clone in shared repository

fatal: destination path '/path/to/shared/repository/shared.git' already exists and is not an empty directory.

接下来我决定克隆共享git存储库,将现有项目中的所有文件添加到具有新存储库的目录,然后添加并将这些文件提交到新存储库,然后使用git push将所有文件放入这些文件位于共享存储库中。这也没有用。我得到的错误是:

No refs in common and none specified; doing nothing.
Perhaps you should specify a branch such as 'master'.
fatal: The remote end hung up unexpectedly
error: failed to push some refs to '/path/to/shared/repository/shared.git'

如何获取现有存储库中的文件并将它们放在共享存储库中?

1 个答案:

答案 0 :(得分:1)

像通常一样创建一个新的空git存储库(例如,名为shared.git)。

将现有存储库克隆为名为shared的目录:

$ git clone url_to_existing.git shared 

然后更改存储库的远程以使origin指向新的创建存储库(URL_OF_SHARED_GITshared.git存储库的URL):

$ cd shared
$ git remote set-url origin URL_OF_SHARED_GIT

然后推送主分支:

$ git push -u origin master

你完成了!

请注意,它只会推送主分支。如果要推送其他分支,则必须对其他分支执行相同操作。要推送代码,请使用git push --tags。现在,如果您克隆shared.git,它将反映您推送的内容。