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,
- Keep at
~/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
pathmaster)
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.