Git 提示 fatal: remote origin already exists(远程来源已经存在)问题解决办法


如果当前目录下已经有远程仓库,就会报如下的错:

fatal: remote origin already exists.

此时,我们可以先 git remote -v 查看远程库信息:

# git remote -v
origin	https://gitee.com/varden99/ansible-playbooks.git (fetch)
origin	https://gitee.com/varden99/ansible-playbooks.git (push)

可以看到,本地库已经关联了origin的远程库,并且该远程库指向Gitee。

解决办法如下:

# git remote remove origin
# git remote add origin https://gitee.com/varden99/ansible-playbooks.git
# git remote -v
origin	https://gitee.com/varden99/ansible-playbooks.git (fetch)
origin	https://gitee.com/varden99/ansible-playbooks.git (push)
# git branch
* main
# git push --set-upstream origin main