git问题:远程来源已经存在

时间:2019-12-22 04:00:27

标签: git github

我正在尝试将代码添加到github,而git令我非常困惑。

这是我的代码,

$ git init 
$ git add . 
$ git commit -m "First commit" 
$ git remote add origin https://github.com/anhbui2904/xxx.git 
$ git push origin master

我的问题是,当我尝试输入代码时

$ git commit -m "First commit"
On branch master Your branch is up to date with origin/master

然后,使用此代码 $ git remote add origin https://github.com/anhbui2904/xxx.git出现此错误fatal: remote origin already exists

我尝试了git fetch --allgit reset --hard origin/master,但仍然无法解决此问题。

我是一个新手,对此问题非常困惑,请给我一些想法吗?非常感谢。

2 个答案:

答案 0 :(得分:1)

您应该为遥控器尝试另一个名称。

ValueKey(unique identification number for your widget)

然后,在按下时,叫这个名字。

git remote add othername https://github.com/anhbui2904/xxx.git

另一种方法是删除当前原点。

git push othername master

然后根据需要添加它。

答案 1 :(得分:0)

如果您想为默认遥控器(origin)尝试另一个URL,请使用git remote set-url ...

git remote set-url origin https://github.com/anhbui2904/xxx.git

您还可以将另一个URL添加为新的远程,然后将提交推送到该URL:

git remote add <a-meaningful-remote-name> https://github.com/anhbui2904/xxx.git
git push -u <a-meaningful-remote-name> master

git pushgit push origin的快捷方式,它将您的提交推送到默认的远程设备origin。如果您想将提交推送到其他远程服务器,请改用git push <your-remote-name>

git remote的一些其他有用命令:

# rename a remote
git remote rename <old-name> <new-name>

# remove a remote
git remote remove <remote-name>

# manual for `git remote`
git remote --help
相关问题