簡體   English   中英

Git - 致命:遠程來源已經存在

[英]Git - fatal: remote origin already exists

我無法使用remote命令遠程創建原點:

$ git remote add origin https://github.com/LongKnight/git-basics.git
fatal: remote origin already exists.

為了解決這個錯誤,我試過這個:

$ git remote -v origin
$ git remote -v show origin

它不會將文件從我的本地存儲庫上傳到遠程:

$ git push -u origin master
fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights and the repository exists.

每個存儲庫都有自己的來源嗎?


解決方案:我使用的是 Github 或 Git Shell 附帶的 Powershell,因為它也被稱為做我的教程,一旦我切換到 Git Bash,它就可以正常工作。

簡單一點:

git remote set-url origin https://github.com/LongKnight/git-basics.git

這將用新的原點替換當前原點。

嘗試這個

git 遠程 rm 起源

然后,

git remote add origin https://yourLink

我遇到了類似的問題,但我使用以下方法解決了它:

git remote set-url origin https://GitHub.com/Fasunle/my_portfolio.git

接着,

git push main master 

它奏效了。

為了使用 git push,你必須在 local_branch 后面指定最終目的地(在我自己的例子中,它是本地分支的 master 和遠程分支的 main)。 然而,它們可能是相同的。 如:

git push -u main local_branch_to_push

或者

git push -u master local_branch_to_push

唔。

為什么你的起源沒有價值,這很奇怪。 通常,它應該如下所示:

[mayur.n@harry_potter]$ git remote -v
origin  /mnt/temp.git (fetch)
origin  /mnt/temp.git (push)

您的來源沒有與之關聯的 url。 它實際上是名稱值對。 所以當你說“git push origin master”時,Git 會替換 origin 的值。 就我而言,它將是“/mnt/temp.git”。

現在你能做什么?

嘗試這個:

1)將存儲庫克隆到另一個目錄中。

2) 運行“ git remote -v ”並獲取origin的值

3)在您的情況下,該值看起來是“ https://github.com/LongKnight/git-basics.git

4)所以回到你的工作目錄,然后運行“ git remote add origin2 https://github.com/LongKnight/git-basics.git

5) 運行“ git remote remove origin

6) 現在運行“ git remote rename origin2 origin

7) 現在用“git remote -v”檢查 origin 的值是多少

8) 現在應該正確設置。 如果是這樣,運行“ git push

暫無
暫無

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

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