2014-05-01 59 views
70

我試圖把我的項目的github的一個,和我不斷收到此錯誤:致命:當前分支主沒有上游分支

[email protected]:~/846156 (master) $ git push 

fatal: The current branch master has no upstream branch. 
To push the current branch and set the remote as upstream, use 

    git push --set-upstream origin master 

於是,我嘗試過了,得到這個:

[email protected]:~/846156 (master) $ git push --set-upstream origin master 

fatal: Authentication failed 

另一個stackoverflow線程建議我嘗試以下,結果令人失望。

[email protected]:~/846156 (master) $ git push -u origin master 

fatal: Authentication failed 

然後我嘗試這樣的:

[email protected]:~/846156 (master) $ git config remote.origin.push HEAD 

[email protected]:~/846156 (master) $ git push 

fatal: Authentication failed 

任何提示?

+1

回購必須存在於github _before_您可以推送到它。可以?你正在與克隆它的回購? – matt

+0

我克隆了Github的repo,然後在自述文件中添加了1行,然後嘗試將其推回。 – user1524361

回答

23

您修復了推送,但與推送問題無關(我在「Why do I need to explicitly push a new branch?」中解釋過:git push -u origin mastergit push -u origin --all),您現在需要解決身份驗證問題。

這取決於你的網址(SSH爲「[email protected]/yourRepo,或https爲https://github.com/You/YourRepo

對於HTTPS URL:

如果您的帳戶是由two-factor authentication保護,您的常規密碼將無法正常工作(用於https url),as explained hereor here

您的密碼包含特殊字符(如this answer)同樣的問題

如果HTTPS不工作(因爲你不希望產生二級密鑰,PAT:個人訪問令牌),那麼你可以切換到ssh,as I have shown here

66

您也可以使用下面的命令:

git push -u origin master 

這將創建(-u)在遠程回購另一個分支。一旦使用ssh進行身份驗證就完成了。

+1

這與問題確實有關,因爲問題在於驗證。他還表示,他已經在他的職位上嘗試過。 –

+6

來自谷歌,這個答案解決了我的問題。 +1 – HAL9000

22

顯然,當您第一次推送時忘記--all參數,您也會收到此錯誤消息。我寫

git push -u origin 

這給了這個錯誤,它應該是

git push -u origin --all 

我多麼喜歡這些複製 - 粘貼錯誤...

+2

謝謝。我在Visual Studio Code中遇到了這個錯誤,並且這個工作很奏效,但是在多個開發人員的環境中,有人可以解釋這是什麼嗎? – o365spo

0

的計算機和您的GitHub相關。使用SSH。計算機代碼,所以你不需要提交驗證enter image description here

2. git無法管理空文件夾。所以你必須寫一個這樣的readme.md保存在一個文件中。否則,您將無法找到該文件。

3.您的本地項目並不是新項目移過來的。請

git init

git remote add origin +"githublink"

git add .

git commit -m ""着呢。

4.然後git pull origin master(關鍵)

5.最後git push origin master(解決所有的問題)。

http://my.oschina.net/psuyun/blog/123005參考鏈接

2

首先使用git pull origin your_branch_name 然後use git push origin your_branch_name

+0

對不起如果這聽起來很愚蠢。如何瞭解我的分行名稱。我的回購在AWS中。 – Pravin

2

您需要配置遠程第一,然後推。

git remote add origin url-to-your-repo 

Actual Instructions

1

有一個簡單的解決方案,這裏面爲我工作在MacOS塞拉利昂。 我做了以下兩條命令:

git pull --rebase git_url(Ex: https://github.com/username/reponame.git) 
git push origin master 

如果顯示有任何未來的推後,關於上游的任何致命錯誤,然後只需運行:

git push --set-upstream origin master 
-1

要解決此問題,而從git自己檢查出的代碼,U需要給命令象下面這樣:

git checkout -b branchname origin/branchname

這裏,由德我們正在設置the upstream branch,所以你不會面臨上述問題。

相關問題