user128511
user128511

Reputation:

How do I clone a local git folder(repo) to a remote server

I see this question asked many times. I've tried every answer.

Not one of them has actually worked. Maybe something changed in git since they were written?

To be clear: I have a local checkout, I want a similar checkout on remote. I know I can use scp -r . ssh://remote/somefolder but scp is extremely slow so I'd prefer to do it with git.

Some answers said

Other answers said

This fails. Now somefolder is full of git files instead of having a .git folder

Okay let's guess

Hey I have a .git folder inside somefolder

Let's push

The question I want answered is, how do I push a local repo to a remote server such that on the remote server it acts exactly the same as if I had cloned the repo.

In other words if I could do this

I can't do that though since local doesn't have public ip address serving ssh. So instead I want to push it. When it's done remote should have

somefolder
|
+- .git

and the master branch should be checked out, just like it would if I had cloned.

Upvotes: 0

Views: 975

Answers (2)

Haldean Brown
Haldean Brown

Reputation: 12721

What if you do exactly what it says in the error message:

remote: error: You can set 'receive.denyCurrentBranch' configuration variable to
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into
remote: error: its current branch; however, this is not recommended unless you
remote: error: arranged to update its work tree to match what you pushed in some
remote: error: other way.

Run this in the remote, non-bare repository:

git config receive.denyCurrentBranch ignore

The warning is there for a reason, though; this will interact poorly with edits to the working tree on remote. If you do this, never edit files directly on the remote without committing them!

Upvotes: 1

Constantin Galbenu
Constantin Galbenu

Reputation: 17713

How about this:

on remote:

$ mkdir somefolder
$ cd somefolder
$ git init --bare

on local

$ git push ssh://remote/somefolder/

on remote again, only first time

$ mkdir someotherfolder
$ cd someotherfolder
$ git clone somefolder .

on remote again, subsequent calls $git pull

I think you could do this automatically, on subsequent calls with hooks

Upvotes: 1

Related Questions