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,
~/git/onefile
a non-bare git repo containing one innocuous file such as .gitignore
. (Alternatively, create such a repo dynamically.)(cd ~/git/onefile; git push
path master)
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.
You can now clone your new repository by doing the following: git clone /org/centers/foo/repos/private/bar Initialized empty Git repository in /tmp/bar/. git/ warning: You appear to have cloned an empty repository. As you can see, the --all created the remote master branch for you.
You can specify the destination directory as second parameter of the git clone command, so you can do: git clone <remote> . This will clone the repository directly in the current local directory. This works only if current directory isn't empty.
Usage. git clone is primarily used to point to an existing repo and make a clone or copy of that repo at in a new directory, at another location. The original repository can be located on the local filesystem or on remote machine accessible supported protocols. The git clone command copies an existing Git repository.
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:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With