【问题标题】:Problems with pushing changes -- git推送更改的问题——git
【发布时间】:2022-01-28 07:29:03
【问题描述】:

我在将更改从 Visual Studio 代码推送到 Github 时遇到了困难。对于上下文,我对 git 和 github 相对较新——在查看了过去的 SO 讨论和其他在线论坛之后,并尝试了以下操作:使用 git init/git remote origin 将本地计算机与 github 连接,以及生成 SSH 密钥.

但是,这些东西似乎都不起作用。当我输入时

git push -u origin master

终端回复error: src refspec master does not match any

另外,我不确定这是否相关,但是当我输入时

~/.ssh/config

终端回复the term '~/.ssh/config' is not recognized as the name of a cmdlet, function, script file, or operable program.

任何有关故障排除的想法都将不胜感激。谢谢大家!

【问题讨论】:

    标签: git github push


    【解决方案1】:

    error: src refspec master does not match any 表示本地仓库没有名为 master 的分支。它可以是main 或其他名称。运行git branch 列出本地分支。而当前签出的名字前有一个*

    关于第二个错误,当你输入~/.ssh/config 时,它会尝试执行这个文件。但该文件不可执行(也不应该如此),而且它不是 cmdlet、函数、脚本文件或可运行的程序。

    第一个错误与~/.ssh/config无关。

    【讨论】:

    • 非常感谢您的回复!当我运行“git branch”时,我得到了“* main”,所以我相信这应该很好。但是当我运行“git push origin main”时,终端给了我“ssh:连接到主机 github.com 端口 22:连接超时致命:无法从远程存储库读取。”这可能是因为我目前在 Github 存储库上还没有任何文件(即我试图推送其更改的文件现在仅存储在本地)?
    【解决方案2】:

    当我运行“git push origin main”时,终端给了我

    ssh: connect to host github.com port 22: 
         Connection timed out 
    fatal: Could not read from remote repository.
    

    这取决于您的上下文,但在我的公司环境中,SSH 对于传出查询是关闭的。
    这意味着我必须使用 HTTPS URL(在creating a Personal Access Token 之后,用作密码)

    cd /path/to/local/repository
    # if you had already defined "origin"
    git remote set-url origin https://github.com/me/MyNewRepo
    

    别忘了先在 GitHub 上创建一个空的“myNewRepo”存储库。

    您可以直接从您的工作站执行此操作。
    Install GitHub CLI gh,并且:

    cd /path/to/local/repository
    gh repo create myNewRepo --source=.
    

    【讨论】:

      猜你喜欢
      • 2019-04-05
      • 1970-01-01
      • 1970-01-01
      • 2022-11-12
      • 1970-01-01
      • 2013-06-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多