I have been trying to figure this one out but I am having a hard time doing so. I am currently working on an open source project that requires me to allow a user to push to remote repository without it already existing there. I want to avoid manually logging in to a server and running git init
or git init --bare
.
For obvious reasons, I get the following error when trying to push my local repository to a path that doesn't point to an existing repository on the remote server:
fatal: '/var/repositories/myrepo' does not appear to be a git repository
fatal: The remote end hung up unexpectedly
But I would like to be able to run for example the following command:
git push origin master
And have that create /myrepo
in /var/repositories
if it does not yet exist. How would I be able to accomplish this? I would assume it is some kind of (global) git config setting you would probably set on the remote server, or otherwise a (repository specific) git config locally, but I couldn't figure it out.
Any help would be much appreciated!
Thanks!
There is currently no way to use git push
to create a repository on the remote. The best you can do is write a one-liner script something like this:
#!/bin/bash
ssh $1 "git init --bare $2" &&
git push ssh://$1/$2
Hopefully you can ssh in; if you can't, you could use some kind of filesystem access to just manually create the repo by dumping in the appropriate file/directory structure (maybe create it locally and copy). You might also create a named remote along the way.
This was actually one of the most requested features on the 2010 Git Survey - so maybe you'll get your wish sometime in the next year!