Git remote repository (with files?)

2019-08-12 09:12发布

I have a remote web server that I have full access to (ssh, git, etc.). I want to be able to edit files on my computer and push them to the remote server. When I use a bare repository it doesn't change the file, but when I use a non-bare repository it complains with the following message:

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 t
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing int
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 som
remote: error: other way.
remote: error: 
remote: error: To squelch this message and still keep the default behaviour, se
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.

Is there any way to get working copies on both my laptop and the remote server?

Thanks

1条回答
Viruses.
2楼-- · 2019-08-12 10:02

You can either set that option (on the server):

git config receive.denyCurrentBranch ignore

Or use two repositories on the server side. One is the bare repository that you push to. The other one is a non-bare repository which is a "working copy" clone of the bare repo. You give the bare repo a post-commit hook that cds into your working copy and executes a git pull.

查看更多
登录 后发表回答