I have a server named production with git source code checked out from master branch and executed.
In addition I have a development server with the clone of the git repo where I do code modifications.
I would like to sync the source code development -> production.
My initial idea was running git pull --rebase on the production server to get the up-to-date commited files. However, because of network constraints (firewall etc') production can't contact development but the other way around works: development can git pull/push from production.
When I tried to push I got the following message:
+ git push origin master
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'.
What I understand is that in order to push changes that I should configure receive.denyCurrentBranch and then after push execute git reset --hard on production master branch. This will in addition overwrite uncommitted changes on production.
Is there a safer way doing that? For example sometimes someone might ssh to production machine and change the code there directly. I prefer my command will fail in such case. Another example is that the production server has some untracked files that I am afraid to overwrite/delete.
Is there another way other than the git reset --hard on production server?