我试图按照迈克尔哈特尔的Rails教程,但我遇到了一个错误。
我在GitHub注册了,发放了一个新的SSH密钥,并创建了一个新的存储库。但是当我在终端中输入下一行时,我得到了以下错误:
Parkers-MacBook-Pro:.ssh ppreyer$ git remote add origin git@github.com:ppreyer/first_app.git
fatal: remote origin already exists.
只是想知道是否有人遇到过这个问题?
我试图按照迈克尔哈特尔的Rails教程,但我遇到了一个错误。
我在GitHub注册了,发放了一个新的SSH密钥,并创建了一个新的存储库。但是当我在终端中输入下一行时,我得到了以下错误:
Parkers-MacBook-Pro:.ssh ppreyer$ git remote add origin git@github.com:ppreyer/first_app.git
fatal: remote origin already exists.
只是想知道是否有人遇到过这个问题?
短版:
您只需更新现有的远程:
$ git remote set-url origin git@github.com:ppreyer/first_app.git
长版:
正如错误消息所示,已经有一个配置了相同名称的远程服务器。因此,您可以使用不同的名称添加新的远程设备,如果不需要的话,也可以更新现有的远程设备。
要添加一个新的远程,例如,调用github而不是origin(显然已经存在于您的系统中),执行以下操作:
$ git remote add github git@github.com:ppreyer/first_app.git
记住,尽管在教程中你看到“起源”,你应该把它换成“github”。例如$ git push origin master现在应该是$ git push github master。
但是,如果你想查看已经存在的原始远程是什么,你可以执行$ git remote -v。如果你认为这是由于一些错误,你可以这样更新它:
$ git remote set-url origin git@github.com:ppreyer/first_app.git
您可以看到配置为通过哪些远程存储库连接
git remote -v
将返回如下格式的列表:
origin git@github.com:github/git-reference.git (fetch)
origin git@github.com:github/git-reference.git (push)
这可能会帮助你弄清楚最初的“原点”指的是什么。
如果你想保留你用-v看到的远程连接,但仍然想遵循Rails教程,而不必记住'github'(或其他一些名称)用于教程的repo,你可以使用命令重命名你的其他存储库:
git remote rename [current name] [new name]
如:
git remote rename origin oldrepo
然后您应该能够继续您的教程。
对于那些遇到非常常见的错误“fatal: remote origin already exists.”,或者当试图删除origin时得到“error: could not remove config section remote.”原点”,你需要做的就是手动设置原点。
Windows的POSH~Git for Windows PowerShell(和GitHub for Windows的应用程序)在这方面有一个问题。
就像我经常遇到的那样,我又一次在布置我的章鱼女时遇到了这种情况。这就是我如何让它工作的。
首先,检查你的遥控器:
C:\gd\code\octopress [source +2 ~3 -0 !]> git remote -v
octopress https://github.com/imathis/octopress.git (fetch)
octopress https://github.com/imathis/octopress.git (push)
origin
您首先会注意到我的原点没有url。任何删除它、重命名它的尝试都失败了。
因此,手动更改url:
git remote set-url --add origin https://github.com/eduncan911/eduncan911.github.io.git
然后你可以再次运行git remote -v来确认它是有效的:
C:\gd\code\octopress [source +2 ~3 -0 !]> git remote -v
octopress https://github.com/imathis/octopress.git (fetch)
octopress https://github.com/imathis/octopress.git (push)
origin https://github.com/eduncan911/eduncan911.github.io.git (fetch)
origin https://github.com/eduncan911/eduncan911.github.io.git (push)
这已经修复了数十个我遇到的问题,GitHub, BitBucket GitLab等。
这工作:
git remote rm origin
git remote add origin git@github.com:username/myapp.git
首先做一个:
git remote rm origin
然后
git remote add origin https://github.com/your_user/your_app.git
瞧!为我工作!
如果你需要检查你已经连接到本地回购的远程回购,有一个cmd:
git remote -v
现在,如果你想删除远程回购(比如,origin),那么你可以做的是:
git remote rm origin
如果你已经为另一个存储添加了项目,比如你上传到github,然后你上传到bitbucket,然后它会显示这种类型的错误。
如何删除错误:删除git-hub文件,然后重复以下步骤…
git init
git remote add origin git@bitbucket.org:Yourname/firstdemotry.git
git add -A
git commit -m 'Message'
git push -u origin master
该错误消息表明您的git目录中已经有一个远程服务器。 如果您对那个遥控器感到满意,您就可以推送您的代码。如果没有或者你不能推,就:
git remote remove origin
git remote add origin git@github.com:ppreyer/first_app.git
瞧!
remote的概念就是远程存储库的URL。
原点是指向该URL的别名。因此,我们不需要在每次想要将东西推送到存储库时都写入整个URL,只需使用这个别名并运行:
Git push -u origin master
告诉git将我们的代码从本地主分支推到远程源存储库。
每当我们克隆一个存储库时,git默认为我们创建这个别名。此外,每当我们创建一个新的存储库时,我们只是自己创建它。
不管它是什么情况,我们总是可以把这个名字改为任何我们喜欢的,运行这个:
git remote rename [current-name] [new-name]
由于它存储在git应用程序的客户端(在我们的机器上),更改它不会影响我们的开发过程,也不会影响我们的远程存储库。记住,它只是一个指向地址的名称。
这里通过重命名别名所做的唯一更改是,每次将内容推入存储库时都必须声明这个新名称。
Git push -u my-remote-alias master
显然,一个名字不能指向两个不同的地址。这就是为什么您会得到这个错误消息。在本地机器上已经有一个名为origin的别名。要查看你有多少个别名,它们是什么,你可以启动这个命令:
git remote -v
这将显示您拥有的所有别名以及相应的url。
你也可以删除它们,如果你喜欢运行这个:
git remote rm my-remote-alias
简而言之:
看看你已经有了什么, 删除或重命名它们, 添加您的新别名。
快乐的编码。
在特殊情况下,您正在从用作模板的旧存储库开始创建新的存储库(如果不是您的情况,请不要这样做)。完全擦除旧存储库的git文件,这样你就可以开始一个新的存储库:
rm -rf .git
然后像往常一样重新启动一个新的git存储库:
git init
git add whatever.wvr ("git add --all" if you want to add all files)
git commit -m "first commit"
git remote add origin git@github.com:ppreyer/first_app.git
git push -u origin master
$ git remote add origin git@gitlab.com:abc/backend/abc.git In this command origin is not part of command it is just name of your remote repository. You can use any name you want. First You can check that what it contains using below command $ git remote -v It will gives you result like this origin git@gitlab.com:abc/backend/abc.git (fetch) origin git@gitlab.com:abc/backend/abc.git (push) origin1 git@gitlab.com:abc/backend/abc.git (fetch) origin1 git@gitlab.com:abc/backend/abc.git (push) if it contains your remote repository path then you can directly push to that without adding origin again If it is not contaning your remote repository path Then you can add new origin with different name and use that to push like $ git remote add origin101 git@gitlab.com:abc/backend/abc.git Or you can rename existing origin name add your origin git remote rename origin destination fire below command again $ git remote -v destination git@gitlab.com:abc/backend/abc.git (fetch) destination git@gitlab.com:abc/backend/abc.git (push) It will change your existing repos name so you can use that origin name Or you can just remove your existing origin and add your origin git remote rm destination
要查看您有多少个别名以及它们是什么,您可以启动这个命令 Git remote -v
然后查看您在哪个存储库中 那就试试 git remote set-url——add[然后你的存储链接] Git push -u origin master
至少在bash上,我们可以强制命令的退出代码的返回值为0
您可以删除旧的远程并重新添加它
git remote remove $1 || true
git remote add $1 $2
在Windows上使用git bash将存储库添加到git hun时遇到同样的错误
git remote add origin https://github.com/axaysushir/netflix_page_clone.git
致命:远程源已经存在。
fatal: remote origin already exists.
! [rejected] master -> master (fetch first)
错误:无法将一些引用推到“https://github.com/axaysushir/meditation_app_using_js.git”
通过以下命令更新存储库
$ git remote set-url origin https://github.com/axaysushir/netflix_page_clone.git
然后添加存储库使用git远程添加github而不是git远程添加起源
$ git remote add github https://github.com/axaysushir/netflix_page_clone.git
然后写以下命令,而不是git push origin master,这将把你的存储库上传到github
$ git push github master
使用此命令更新已经存在的源
git remote set-url origin https://github.com/SriramUmapathy/ReduxLearning.git
我在远程推送代码时,在Bitbucket中面临问题
遵循以下步骤:
步骤1:更新现有的远程
git remote set-url origin https://pratik@bitbucket.org/pratik/demoapp.git
步骤2:您可以使用此命令强制使用本地存储库对服务器进行更改。远程回购代码将被本地回购代码取代。
git push -f origin master
-f通常,该命令拒绝更新不是用来覆盖它的本地引用的祖先的远程引用。
请将“git remote add origin git@github.com”中的“add”替换为“git remote set-url origin git@github.com”中的“set-url
git remote set-url origin https://username:PERSONAL_ACCESS_TOKEN@github.com:ppreyer/first_app.git
git push -u origin main
你可以在github上使用以下步骤生成个人访问令牌:
转到设置 点击开发者设置 单击Generate new token 生成您的个人访问令牌并将其粘贴到上面的命令上。:)
如果你得到一个类似“错误:远程源已经存在”的错误。 然后,请尝试以下命令删除已经存在的远程源
git remote remove origin
然后使用你的命令
git remote add origin git@github.com:ppreyer/first_app.git
如果您不想删除现有的远程记录,请更新它
git remote set-url <REMOTE-NAME> <NEW-URL>
然后使用你的命令
git remote add origin git@github.com:ppreyer/first_app.git
如果要重命名现有项目,请使用以下命令
git remote rename <old-name> <new-name>
如果要将原始远程重命名为backup。你只需运行:
git remote rename origin backup
谢谢你! !