Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
526 views
in Technique[技术] by (71.8m points)

git - Git推送错误“ [[远程拒绝]主机->主机(分支当前已签出)”)(Git push error '[remote rejected] master -> master (branch is currently checked out)')

Yesterday, I posted a question on how to clone a Git repository from one of my machines to another, How can I 'git clone' from another machine?

(昨天,我发布了一个有关如何将Git存储库从我的一台计算机克隆到另一台计算机的问题如何从另一台计算机“ git clone”?)

.

(。)

I am now able to successfully clone a Git repository from my source (192.168.1.2) to my destination (192.168.1.1).

(现在,我可以成功地将Git存储库从源(192.168.1.2)克隆到目标(192.168.1.1)了。)

But when I did an edit to a file, a git commit -a -m "test" and a git push , I get this error on my destination (192.168.1.1):

(但是,当我对文件, git commit -a -m "test"git push ,我在目的地(192.168.1.1)上收到此错误:)

git push                                                
[email protected]'s password: 
Counting objects: 21, done.
Compressing objects: 100% (11/11), done.
Writing objects: 100% (11/11), 1010 bytes, done.
Total 11 (delta 9), reused 0 (delta 0)
error: refusing to update checked out branch: refs/heads/master
error: By default, updating the current branch in a non-bare repository
error: is denied, because it will make the index and work tree inconsistent
error: with what you pushed, and will require 'git reset --hard' to match
error: the work tree to HEAD.
error: 
error: You can set 'receive.denyCurrentBranch' configuration variable to
error: 'ignore' or 'warn' in the remote repository to allow pushing into
error: its current branch; however, this is not recommended unless you
error: arranged to update its work tree to match what you pushed in some
error: other way.
error: 
error: To squelch this message and still keep the default behaviour, set
error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
To git+ssh://[email protected]/media/LINUXDATA/working
! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to 'git+ssh://[email protected]/media/LINUXDATA/working'

I'm using two different versions of Git (1.7 on the remote and 1.5 on the local machine).

(我正在使用两种不同的Git版本(远程版本为1.7,本地计算机版本为1.5)。)

Is that a possible reason?

(那可能是原因吗?)

  ask by hap497 translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can simply convert your remote repository to bare repository (there is no working copy in the bare repository - the folder contains only the actual repository data).

(您可以简单地将远程存储库转换为裸存储库(裸存储库中没有工作副本-文件夹仅包含实际的存储库数据)。)

Execute the following command in your remote repository folder:

(在远程存储库文件夹中执行以下命令:)

git config --bool core.bare true

Then delete all the files except .git in that folder.

(然后删除该文件夹中除.git以外的所有文件。)

And then you will be able to perform git push to the remote repository without any errors.

(然后,您将能够执行git push到远程存储库,而不会发生任何错误。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...