2012-12-06 112 views
3

我從個人git服務器克隆一個空的存儲庫。最初推後(push -u origin master)我有一些錯誤,但我推到裏面。Git拉和推不工作

試圖用git push顯示以下內容:

No refs in common and none specified; doing nothing. Perhaps you should specify a branch such as 'master'. fatal: The remote end hung up unexpectedly error: failed to push some refs to 'link-top-repository'

然後我試圖git push origin master

Counting objects: 3, done. 
Writing objects: 100% (3/3), 218 bytes, done. 
Total 3 (delta 0), reused 0 (delta 0) 
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'. 

問題開始使用時git pull

Your configuration specifies to merge with the ref 'master' from the remote, but no such ref was fetched.

我嘗試檢查的.git /配置,但它似乎是正確的。

[core] 
     repositoryformatversion = 0 
     filemode = true 
     bare = false 
     logallrefupdates = true 
     ignorecase = true 
[remote "origin"] 
     fetch = +refs/heads/*:refs/remotes/origin/* 
     url = [email protected]:/repository/regulator 
[branch "master"] 
     remote = origin 
     merge = refs/heads/master 
[branc "master"] 
     remote = origin 

有什麼建議嗎?

+0

可能的重複:http://stackoverflow.com/questions/11117823/git-push-error-refusing-to-update-checked-out-branch – jchapa

回答

0

從文件末尾刪除此文件。

[branc "master"] 
     remote = origin 

而且 - 您的中心Git倉庫,其中開發人員push來,應該是一個純倉庫。你的錯誤日誌顯示你的錯誤不是。

+0

刪除了2行。但沒有任何改變。都一樣。 –

+0

看起來像推到一個非裸倉庫。這是爲什麼? – Rawkode

+0

所以我需要創建的庫是--bare? –

5

假設您有權訪問您的個人git服務器,您正在做的是將更改推送到non-bare repository以及當前作爲工作目錄簽出的分支。

目前的常見良好做法總是推到裸倉庫。要創建它,你可以做這樣的事情:

git init --bare SomeRepo.git 

如果你堅持推到非純倉庫,這是不推薦使用,請確保您要推到分支是不當前檢出分支或當前工作目錄。只是打開一個命令行工具,如在Linux終端或混帳的bash在Windows中,移動到你的資料庫目錄(即中有一個文件夾中的.git的一個),執行此命令:

git branch -v 

它會顯示目前已簽出該存儲庫,和分支的所有可用的樹枝上標有「*」,例如:

* master  b0bb0b1 some commit message 
    development babbab2 some other commit message 
    experimental bebbeb3 some commit message in experiment 

上面的例子表明,主是當前簽出的分支,因此你不能推動它。但是你可以推動其他分支,比如開發或者實驗。如果你一定要推到大師,你可以通過改變當前目錄中的其他分支做到這一點,使用這個命令:

git checkout the_branch_name 

在這之後,目前已簽出的是上面的命令中指定的分支,推掌握現在是可能的。

0

我也有類似的問題,發現在Unix堆棧交換答案: https://unix.stackexchange.com/a/166713

In my case, my local branch and remote branch had different capitalization.

To resolve this I deleted my local branch $ git branch -d branch-name , then checked out the remote branch again using $ git fetch and $ git checkout Branch-name .

所以刪除本地分支,檢查出的遠程分支再次固定它。