I used Mercurial (Hg) before, and it was ok to do something like at the local PC:
hg clone ssh://peter@hostingcompany.com/~/mysite.com
and
I don't know why people are saying it's not supported. While pushing to a bare repo is the recommended practice, you can push to a non-bare by setting the receive.denyCurrentBranch
config variable to 'ignore' or 'warn' as shown by the error message you get (at least on 1.7.1) when you try to do it:
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.
I would say your workflow where you deploy with a git push followed by a hard reset on the remote side is precisely the exception to the rule for which this config variable was created.
Also, I haven't tried it personally, but the "current branch" language implies you can push to a remote branch that isn't checked out with no errors at all, after which you could do a fast-forward merge on the remote end into your checked out branch.
You should only push to bare repositories (a bare repository has no working copy).
You have two solutions:
EDIT my guess that the remote repo has local modifications is wrong; don't know why you can't push, but the rest of my post is still valid: you shouldn't push to normal repos.
In Git, you are only supposed to push to a bare repository. The best solution is to create a bare repository on the server that you push to, and then a non-bare clone of it which contains the checkout, so after you push to the bare repo, you SSH to the server and do git pull
from the non-bare repo (or set up a hook to do so automatically after the bare repo receives the new version).
In Git it is usually a good practice to have the repo on the server to which other people push to be a bare repository. It is highly recommended.
git init . --bare
Here it is failing because you are pushing to a non-bare ( with a working copy ) repo and to the branch that is checked out.
Git does not support pushing to a branch, that is checked out at the remote end.
The recommended way is to use bare repository on the server. Normally you either push to the repository (and make it bare) or work on it, but not both. Even if you want to have a working copy on the server, I'd suggest you look at this question.
So you have two options:
mysite.com.git
) and a non-bare repository (mysite.com
). In the bare repository, add a post-update
hook to git --git-dir=.../mysite.com pull
Make just one repository and:
Detach the head: git checkout master@{0}
Add a post-update
hook to git merge master
The reason here is that git refuses to modify the checked-out branch, but if you uncheckout the branch, you will be able to push. And you will be able to update the working directory from a hook (hook is a script placed in hooks
directory in the repository). You can either create a separate branch and check out that, or you can use the "detached HEAD" state (as suggested above—git remembers which branch is checked out by having a special reference "HEAD" that points to the branch, but if you check out something, that is not a branch, it is made to point to a revision directly and that's called a "detached branch" and since no branch is checked out, allows you to push to any of them).