Solution git of "remote: error: reusing to update checked out branch: refs / heads / Master"

Keywords: Operation & Maintenance git

Remote: error: reusing to update checked out branch: refs / heads / Master

 

When using Git Push code to data warehouse, the following error is prompted:

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

Error prototype

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@192.168.1.X:/var/git.server/.../web

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

error: failed to push some refs to 'git@192.168.1.X:/var/git.server/.../web'

terms of settlement:

This is because git rejects the push operation by default and needs to be set. After modifying the. git/config file, add the following code:

[receive]
denyCurrentBranch = ignore

The reason and solution of not being able to view the files in git after push

Best used when initializing a remote warehouse

git --bare init

Instead of using: git init

The specific differences between git init and git --bare init: http://blog.haohtml.com/archives/12265

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

If git init is used for initialization, the directory of the remote warehouse also contains the work tree. When the local warehouse pushes to the remote warehouse, if the remote warehouse is on the branch of the push (if it is not on the branch of the push at that time, there is no problem), then the result of the push will not be on the work tree, that is, the corresponding file in the directory of the remote warehouse is still the previous content.

resolvent:

You must use the command git reset --hard to see the content after push.

After a long study of the solution, I found an order to make it work:

Log in to the remote folder using

git config --bool core.bare true

That's it.

Post a reference 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 add is 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/refs not 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 create another repository elsewhere, 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

Posted by mdub2112 on Fri, 18 Oct 2019 15:00:16 -0700