How to push a Git repository to a folder over SSH

git

I have a folder called my-project inside which I've done git init, git commit -a, etc.

Now I want to push it to an empty folder at /mnt/foo/bar on a remote server.

How can I do this?

I did try, based on what I'd read:

cd my-project
git remote add origin ssh://user@host/mnt/foo/bar/my-project.git
git push origin master

which didn't seem right (I'd assume source would come before destination) and it failed:

fatal: '/mnt/boxee/git/midwinter-physiotherapy.git' does not appear to be a git repository
fatal: The remote end hung up unexpectedly

I'd like this to work such that I don't have to access the remote host and manually init a Git repository every time … do I have to do that? Am I going down the right route at all?

Thanks.

Best Answer

The command is correct; however, the remote address must point to an initialized Git repository too. It's a one-time job, though.

ssh user@host "git init --bare /mnt/foo/bar/my-project.git"

(In Git, a "bare" repository is one without a working tree.)

Related Question