[Solved] Git remote:error:refusing to update checked out branch:refs/heads/master”

remote:error:refusing to update checked out branch:refs/heads/master”

When using Git to push code to a data repository, the following error is prompted:</p

[remote rejected] master -> master (branch is currently checked out)

Prototype 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 [email protected]:/var/git.server/…/web

! [remote rejected] master -> master (branch is currently checked out)

error: failed to push some refs to ‘[email protected]:/var/git.server/…/web’

Workaround:

This is because git rejects push operations by default, and needs to be set up by modifying the .git/config file followed by the following code:</p

[receive]
denyCurrentBranch = ignore</p

Reasons and solutions for not being able to view files in git after a push</p

It’s best to use when initializing remote repositories</p

git –bare init</p
</blockquoteInstead of using: git init</p

Specific difference between git init and git –bare init:http://blog.haohtml.com/archives/12265</p

=================================================

If you use git init to initialize, the remote repository’s directory also contains the work tree, so when the local repository pushes to the remote repository, if the remote repository is on the branch that is being pushed (which is fine if it is not on the branch that is being pushed), then the results of the push will not be reflected in the work tree, i.e., in the The files in the remote repository’s directory are still the same as before. </p

Solution:

You must use the command git reset –hard to see the contents of the push. </p

I researched for a long time and found a command that worked:</p

Log in to the remote folder and use

git config –bool core.bare true</p

And you’re done.

Post a reference to the article.

Create a bare GIT repository

A small rant: git is unable to create a normal bare repository by itself. Stupid git indeed.

To be precise,it is not possible to clone empty repositories. So an empty repository is a useless repository. Indeed, you normally create an empty repository and immediately fill it:

git init git add .

However,git addis not possible when you create a bare repository:

git –bare init git add .

gives an error “fatal: This operation must be run in a work tree”.

You can’t check it out either:

Initialized empty Git repository in /home/user/myrepos/.git/ fatal:http://repository.example.org/projects/myrepos.git/info/refsnot found: did you run git update-server-info on the server?git –bare init git update-server-info # this creates the info/refs file chown -R <user>:<group> . # make sure others can update the repository

The solution is to createanother repositoryelsewhere, add a file in that repository and, push it to the bare repository.

mkdir temp; cd temp git init touch .gitignore git add .gitignore git commit -m “Initial commit” git push <url or path of bare repository> master cd ..; rm -rf temp

Similar Posts: