Here's what I've done so far:
I successfully cloned my remote repo to a new directory on my local machine.
Then I edited a file in working copy, committed it, and tried to push it to the remote repo. Here's the error I got:
$ git push origin master
[email protected]'s password:
Counting objects: 9, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 456 bytes | 0 bytes/s, done.
Total 5 (delta 4), reused 0 (delta 0)
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 inconsist
remote: error: with what you pushed, and will require 'git reset --hard' to matc
remote: error: the work tree to HEAD.
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: To squelch this message and still keep the default behaviour, set
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
To [email protected]:/var/www/html
! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to '[email protected]:/var/www/html'
Do you have any ideas on how I can resolve this? Thanks.
Here's my local Git cofiguration:
$ git config -l
gui.geometry=887x427+26+26 171 192
The remote master-branch is obviously in a non-bare state, which means, that anyone pushing into this branch would overwrite the existing status of the checked out working copy (the reference to HEAD). This is not a good thing.
To solve this, you either use a bare repository as a "communal" repo (do this with 'git init --bare'), or work with branches:
git checkout -b myBranch
Do your work on this branch and commit. Then push your branch with 'git push origin myBranch' without having to destroy anything. After that, your branch in the remote repo can be merged or rebased into master.
Isn't the long description in the message clear enough?
You can do three things:
possibly even force push would work, I don't suggest that.