What's the most straightforward way to clone an empty, *bare* git repository?

荒凉一梦 提交于 2019-11-30 08:36:00
VonC

May be just have a git repo with the minimum number of file in it:

one: .gitignore with obvious ignore patterns in it.

And then clone that "almost empty" repository.
Note that such an "almost empty" repository ("almost" because it still has a minimal working directory alongside the .git directory) can then by 'git clone --bare' (as illustrated here), making it a true bare repo (but not an "empty" one).
This is that bare repo you can then:

  • clone everywhere you want.
  • or (more importantly) push to (since it is a bare repo)

You have in this thread a good summary of the "other way around" (which I keep here for reference).

$ git-init
$ git-remote add origin server:/pub/git/test.git

For a new project (no code yet) I wanted to make an empty, bare
repository (no working copy) on a remote public server as a starting
point, clone it locally, and gradually create content locally and
push it out to the remote, public server.

To which Junio C Hamano responded:

You prepared an empty bare repository for publishing, and that is very good.

The next step is that you prepare your contents elsewhere. That would be your private working place, i.e. the place you would normally work in).
You push from your private working place into that publishing repository.
Your working place is where the very initial commit should come from, since you are the one who is starting the project.

Note that the private working place does not have to be a clone of the empty one. That actually is backwards. Your work started from your private working place to the publishing one.

You could even clone your private repository to publishing one to make it clear who is the master and who is the copy if you wanted to, but because you already have the bare repository for publishing, just pushing into it is all that is needed.

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