无法将github从ssh重置为https [英] Cannot reset github from ssh to https

查看:32
本文介绍了无法将github从ssh重置为https的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Visual Studio Code Windows上安装了git bash.这是我到目前为止的内容:

I have git bash installed on Visual Studio Code Windows. This is what I have so far:

git push
fatal: No configured push destination.

然后我将远程源设置为https not ssh,因为我有一个大文件,而LFS不能与SSH一起正常工作(至少这就是我在stackoverflow中所说的话,我忘记了)

Then I set remote origin to https not ssh because I have a Large file and LFS doesn't work well with SSH (well at least that's what it said in stackoverflow somewhere, I forget)

$ git init
Reinitialized existing Git repository in C:/xampp7.2/htdocs/folder2-temp/.git/

$ git branch -M main

$ git remote add origin https://github.com/mygithubid/myrepository.git

$ git add .

$ git commit
On branch main
nothing to commit, working tree clean

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

    git push --set-upstream origin main

$ git push --set-upstream origin main
Enter passphrase for key '/c/Users/guestaccount/.ssh/id_rsa': 
Uploading LFS objects:   0% (0/1), 0 B | 0 B/s, done.
batch request: git@github.com: Permission denied (publickey).: exit status 255
error: failed to push some refs to 'ssh://github.com/mygithubid/myrepository.git'

因此,如在stackoverflow上所建议的那样,我尝试了以下方法:

So as suggested on stackoverflow I tried this:

$ git remote -v
origin  ssh://git@github.com/mygithubid/myrepository.git (fetch)
origin  ssh://git@github.com/mygithubid/myrepository.git(push)

好酷.需要将其重置为https://

Ok Cool. Need to reset that to https://

$ git remote set-url origin https://github.com/mygithubid/myrepository.git

好,让我们看看SSH是否已重置为HTTPS

Ok let's see if SSH was reset to HTTPS

$ git remote -v
origin  ssh://git@github.com/mygithubid/myrepository.git (fetch)
origin  ssh://git@github.com/mygithubid/myrepository.git (push)

咬我!

好的,请帮助我从SSH将github重置为https我由衷地卡住了:D

Ok someone please help me reset github to https from SSH I am sincerely stuck :D

推荐答案

当打开 C:/xampp7.2/htdocs/folder2-temp/.git/文件夹时,您应该会看到一个该文件夹中的一堆文件,在这种情况下,感兴趣的文件是 config 文件.

When you open the C:/xampp7.2/htdocs/folder2-temp/.git/ folder, you should see a bunch of files in this folder, and the file of interest in this case is the config file.

当您打开 config 文件时,您会看到什么?应该是这样的:

When you open the config file, what do you see? There should be something like this:

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    ignorecase = true
    precomposeunicode = true
[remote "origin"]
    url = git@github.com/mygithubid/myrepository.git
    fetch = +refs/heads/*:refs/remotes/origin/*

您可能在 [core] 部分下没有相同的设置,但是 [remote"origin""] 部分应该相似.如果要将git repo更改为使用 https 而不是 ssh ,请尝试更改

You might not have the same settings under the [core] section, but the [remote "origin"] section should be similar. If you want to change the git repo to use https instead of ssh, try changing

    url = git@github.com:mygithubid/myrepository.git

    url = https://github.com/mygithubid/myrepository.git

直接在此 config 文件中

. 应该 可以解决您遇到的问题,因此,当您运行 git remote -v 时,现在应该看到

in this config file directly. This should fix the problem you have, so when you run git remote -v, you should now see

$ git remote -v
origin  https://github.com/mygithubid/myrepository.git (fetch)
origin  https://github.com/mygithubid/myrepository.git (push)

如评论部分所述,通常修改 .git 目录中的文件不是最佳做法,因为更改了不应更改的内容 .git 目录可能会破坏此存储库的git工作流程.但是,问题在于这种情况似乎是因为git命令没有按应有的方式修改 .git/config 文件,因此修改了 url = [远程来源"] 是一种使 git 与远程服务器通信的解决方法.

As discussed in the comments section, modifying files within your .git directory is generally not best practice since changing something that you're not supposed to change in the .git directory might corrupt your git workflow for this repo. However, the problem is this case seems to be that the git commands aren't modifying the .git/config file as they should be, so modifying the url = line under the [remote "origin"] would be a workaround to get git to communicate with the remote server.

请注意,我在上面的原始答案中建议的更改不会破坏您的本地git存储库,但请记住,更改/删除 .git 目录中的任何其他文件夹或文件如果您做出重大更改,则可能将其破坏.

NOTE that the changes I suggested above in my original answer will not corrupt your local git repo, but just keep in mind that changing/deleting any of the other folders or files inside the .git directory might corrupt it if you do make a bad change.

我建议的此替代方法可能会使您的本地存储库与远程存储库进行通信,但是您可能应该查看Windows的 git bash 安装并检查选择的选项,因为它看起来像您的某些git命令无法正常运行.如果问题不是出在 git bash 上,则可能是安装程序在安装git时为git配置的其他一些设置-不幸的是,在没有全面了解git配置的情况下,调试这很棘手.您可能需要在这里自己进行一些挖掘:)

This workaround I suggested will probably get your local repo communicating with your remote repo, but you should probably take a look at your git bash installation for Windows and check the options you selected since it looks like some of your git commands aren't working as they should be. If the problem isn't with git bash, it might be some other settings the installer configured for git when you were installing git - unfortunately, debugging this is tricky without a comprehensive understanding of the git configuration, so you might need to do some digging on your own here :)

这篇关于无法将github从ssh重置为https的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆