簡體   English   中英

為什么 github 不拋出錯誤? [remote rejected] master -> master (branch is currently checked out) 和遠程服務器呢?

[英]Why doesn't github throw an error ! [remote rejected] master -> master (branch is currently checked out) and a remote server does?

假設我這樣做。

使用 github

  1. 在本地機器上: git init testrepo

  2. 在 github 上:進行回購測試。git 在 web 界面中按下按鈕

  3. 在本地:

cd testrepo

git remote add origin https://github.com/Someuser/test.git

然后:

touch somefile

git add.

git commit -m 'first'

git push -u origin master

一切都很好,我的somefile已同步到 github 存儲庫。

使用遠程服務器

  1. 在本地機器上: git init testrepo

  2. 在遠程機器上:

git init test.git *

  1. 在本地:

cd testrepo

git remote add origin remotemachine:~/test.git

然后:

touch somefile

git add.

git commit -m 'first'

git push -u origin master

不好了...

錯誤信息。

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

一切看起來都一樣。 為什么 github 的行為不同?

或者,補救措施是什么? 可選 - 因為您會在下面的問題中看到一堆建議的解決方案,但沒有一個被接受的答案。

我知道這個問題Git push error '[remote rejected] master -> master (branch is currently checked out)'

但是它沒有回答我的問題。

*在回答我的問題后,我了解到git init test.git是一種違背慣例的不良做法。 因為它創建了一個文件夾,里面有一個 .git 文件夾。 This.git 文件夾是一個 repo。 新創建的文件夾 APART from.git 中的內容是一個工作空間。

git init test.git --bare ,但是,因為此命令會創建一個test.git文件夾(裸倉庫),對應於上述.git文件夾中的內容。

一切看起來都一樣。

只是看起來。 確實情況不同。

為什么 github 的行為不同?

因為在 GiHub 沒有分支機構被檢出。 位於 GitHub 的存儲庫是空的(沒有工作樹)。

底線:如果要將遠程存儲庫推送到它應該是裸的。

請參閱有關裸存儲庫的這些問題和答案:

Bare 和非 Bare 存儲庫之間的實際區別是什么?

“git init”和“git init --bare”有什么區別?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM