Reputation:
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
on remote
$ mkdir somefolder
$ cd somefolder
$ git init
on local
$ git push --mirror ssh://remote/somefolder
remote: error: refusing to update checked out branch: refs/heads/master
remote: error: By default, updating the current branch in a non-bare repository
remote: error: is denied, because it will make the index and work tree inconsistent
remote: error: with what you pushed, and will require 'git reset --hard' to match
remote: error: the work tree to HEAD.
remote: error:
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.
remote: error:
remote: error: To squelch this message and still keep the default behaviour, set
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
Other answers said
on remote
$ mkdir somefolder
$ cd somefolder
$ git init --bare
This fails. Now somefolder
is full of git files instead of having a .git
folder
Okay let's guess
on remote
$ mkdir somefolder
$ cd somefolder
$ git init --bare .git
Hey I have a .git
folder inside somefolder
Let's push
on local
$ git push --mirror ssh://remote/somefolder/
on remote
$ cd somefolder
$ git status
fatal: This operation must be run in a work tree
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
on remote
git clone ssh://local/somefolder/
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
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
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