Reputation: 3360
I have a web site on a flat-file CMS which I'd like to deploy via Git. I want to be able to work on the site from my local machine and push to the live server, but I also need to be able to write new content through the CMS's web admin panel and get those back down to my machine into my development environment.
What's the best method for doing this? I attempted to simply have the repo on both my machine and the server with the server set up as a remote for my local repo. When I tried to push changes to the server, I get an error.
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'.
I could always change the configuration of the remote to allow this, but I feel there's probably a better solution since this is not allowed by default. What is the best method for achieving this via Git? Ideally, changes made through the admin panel would be committed automatically, but this may be asking too much.
Upvotes: 0
Views: 73
Reputation: 124724
You need 3 repositories for this to work:
You can create a bare repo from any of your existing repos like this:
git clone --bare source destination
UPDATE
This blog post explains an interesting approach where the deployment directory is NOT a Git repository:
http://mattbanks.me/wordpress-deployments-with-git/
Although the work tree itself is not a Git repository, you could still run Git commands like this:
GIT_DIR=/path/to/bare.git
GIT_WORK_TREE=/path/to/work/tree
git status
Personally I use a more sophisticated approach, where I have two sites in deployment: mysite.com and dev.mysite.com so my post-receive hook needs more logic to know which deployment to upgrade, depending on the branch name I push to:
http://www.janosgyerik.com/deploying-new-releases-using-git-and-the-post-receive-hook/
Upvotes: 2
Reputation: 610
If you use SSH key of the server to your git repo, you should be able to commit/push from the server, unlike the deploy key method. But that is not recommended as you might get into trouble by creating a conflict. Because resolving conflicts on the server might be a hectic task.
Upvotes: 0