问题
I am not sure where to search from as the error list is as long as the bottom. But generally this is what I did.
What I did:
git clone url .
git add abc.txt
git commit -m "testing"
git push origin master / git push
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'.
To ../git_abc/
回答1:
You are pushing master
from your clone to the origin repo, where the origin repo itself has master
checked out, and the origin repo is not a bare
repo. GIT
doesn't allow that.
To achieve what you are trying to do,
Either use a bare intermediate repo to which you push, and then pull in from this repo.
git clone --bare <origin/repo> intermediate
On your original local repo
git remote add upstream <path/to/intermediate>
git push upstream master
On your origin repo
git remote add downstream <path/to/intermediate>
git pull downstream master
Or push to some other branch on the origin repo, and merge that branch into the master branch in the origin repo.
From local repo
git push origin master:master_to_be_merged
On origin repo
git checkout master
git merge master_to_be_merged
Or ignore these warnings and push anyway
In this case, you will have to take extra care that nothing is breaking, and this is anyway not recommended.
On origin repo, run
git config receive.denyCurrentBranch ignore
And now from your local clone, do
git push origin master
回答2:
Did you check out a branch?
Try
git checkout your_branch (could be master)
then
git add blah
git commit
git push origin master
来源:https://stackoverflow.com/questions/20062732/git-pushing-into-master-failed