"Remote: Error: refusing to update checked out branch: refs/heads/master" SOLUTION

Source: Internet
Author: User

 

Using git pushCodeWhen arriving at the 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

Remote: Error: 'ignore' or 'warn' in the remote repository to allow pushing

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'

Solution:

This is because git rejects the push operation by default and needs to be set. Add the following code after modifying the. Git/config file:

[Receive]
Denycurrentbranch = ignore

Unable to view the cause and solution of the files in git after push

It is best to use it when initializing a remote Repository

Git -- bare init

Instead of using:Git init

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

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

If git init Initialization is used, the Directory of the remote Repository also contains the work tree. When the local repository is pushed to the remote repository, if the remote repository is on the push Branch (if it is not on the push branch at the time, there is no problem), the push result will not be reflected on the work tree, that is, the file corresponding to the remote repository directory is still the previous content.

Solution:

You must use the GIT reset -- hard command to view the pushed content.

After studying the problem for a long time, I found a command to make it usable:

Log on Remote The folder of, use
Git config -- bool core. Bare true

That's it.

Post a referenceArticle:

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 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

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.