克隆一个空的*裸* git仓库最直接的方法是什么? [英] What's the most straightforward way to clone an empty, *bare* git repository?

查看:297
本文介绍了克隆一个空的*裸* git仓库最直接的方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚完成巡航Google搜索结果,其中包含所有关于git无法克隆空存储库的愚蠢信息。有些灵魂甚至提交了一个补丁。在git升级之前,最简单,最直接的方法是克隆一个空的 git仓库?



理想的解决方案将支持 -o 选项可为远程仓库提供除 origin 以外的名称,并且它可以作为简单的shell脚本,例如 git-clone-empty-repo



(为什么我想这样做:在我们的NetApp文件管理器上建立一个空的git repo,在那里它将被备份,但我想在我的本地硬盘上使用克隆,并且来回推动和拉动。与我一起工作的其他人也会做同样的事情。我创建了一个新的git仓库,我无法克隆一个空仓库让我疯狂。)






编辑:VonC的线程建议:

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

等同于在回购清空时克隆远程回购。这不是我想要的,因为我总是在git clone中使用 -o 选项;我根据它所在的机器或其他令人难忘的标准来命名远程回购。 (如果他们都被称为 origin ,我有太多的回购让他们保持直线。)






编辑:以下答案将被标记为已接受: - )






  1. 保留在〜/ git / onefile 一个包含一个无害文件(如 .gitignore )的非裸Git仓库。 (或者,动态地创建这样的repo。)
  2. (cd〜/ git / onefile; git push em> master)

  3. git clone -o / em> path

换句话说,不要试图克隆空回购,而是在创建它之后,推送一个包含一个无害文件的简单回购。然后它不再是空的,可以克隆。

如果有人没有打败我,我会发布一个shell脚本。



其中一个: .gitignore 中有明显的忽略模式。

然后克隆那个几乎为空的存储库。

请注意,这样一个几乎为空的存储库(几乎,因为它仍然有一个最小的工作目录与.git目录一起)可以通过' git clone --bare '(如此处所示 ),使它成为一个真正的裸回购(但不是空)。

这是裸回购,然后你可以:

    $
  • 或(更重要的是)推到(因为它是裸露的回购)

$




您必须在此主题中详细介绍其他

  $ git-init 
$ git-remote add origin服务器:/pub/git/test.git




对于新项目(没有代码)我想在远程公共服务器上创建一个空的,纯粹的
仓库(没有工作副本)作为起始
点,将其克隆到本地,然后逐步创建本地内容和

将它推送到远程公共服务器。


Junio C Hamano回应:


您为发布准备了一个空的裸仓库,并且
非常好。



下一步是您在别处准备您的内容。
将是您的私人工作地点,即您通常在
工作的地方。)

您从您的私人工作地点
推送到该发布存储库。
您的工作地点是最初的提交应该来自的
,因为您是开始项目的一个



注意,私人工作地点不一定是空白的克隆
。这实际上是倒退。您的工作
从您的私人工作场所开始发布。



您甚至可以将您的私人存储库克隆为发布一个
如果你的
想要明确谁是主人,谁是副本,但是因为你已经有了发行
的裸仓库,所以只需要付出就可以了。



I've just finished cruising the Google search results that contain all the email rants about how stupid it is that git can't clone an empty repository. Some kind soul even submitted a patch. Until git is upgraded, what is the simplest, most straightforward method to clone an empty, bare git repository?

The ideal solution will support the -o option to give the remote repo a name other than origin, and it will be implementable as a simple shell script, e.g., git-clone-empty-repo.

(Why I want to do this: I've set up a bare, empty git repo on our NetApp filer where it will be backed up, but I want to work with a clone on my local hard drive and push and pull back and forth. Other people I work with will be doing the same. I create new git repos a lot and my inability to clone an empty repo makes me crazy.)


EDIT: VonC's thread suggests that

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

is equivalent to cloning the remote repo when the repo is empty. This is not quite what I want because I always use the -o option with git clone; I name the remote repo according to what machine it is on or some other memorable criterion. (I have too many repos to keep them straight if they're all called origin.)


EDIT: The following answer will be marked accepted :-)

To clone an empty, bare repo at path,

  1. Keep at ~/git/onefile a non-bare git repo containing one innocuous file such as .gitignore. (Alternatively, create such a repo dynamically.)
  2. (cd ~/git/onefile; git push path master)
  3. git clone -o name path

In other words, don't attempt to clone the empty repo, but rather after creating it, push to it a simple repo containing one innocuous file. Then it is no longer empty and can be cloned.

If someone does not beat me to it, I will post a shell script.

解决方案

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.

这篇关于克隆一个空的*裸* git仓库最直接的方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆