【问题标题】:Novice GitHub question. No ssh problem; how to push a file?新手 GitHub 问题。没有 ssh 问题;如何推送文件?
【发布时间】:2021-11-18 08:46:27
【问题描述】:

早上好, 在网上 4 小时无用的教程之后,我在这里问我的问题。

  1. 我已创建 SSH 密钥并将其添加到 Github
  2. 然后我在 GitHub.com 上创建了一个名为“Repo”的存储库
  3. 然后我在我的计算机上创建了一个名为“Repo”的文件夹,并像往常一样初始化了 git:git.init 等...
  4. 但是,如果我想推一些东西,让我们说 README.md,之后:
git add README.md
git commit README.md

git status 返回"On the main branch Your branch is in advance of 3 commits upon 'origin/main' (Use "git push" to publish these local commits) Nothing to valid, the copy of your work is clean"

但是当我写的时候:

git push README.md

我明白了

"Please make sure you have the correct access rights and the repository exists"

那么,解释是什么? ssh -T git@github.com 返回:“嗨 Aurelien!您已成功通过身份验证,但 GitHub 不提供 shell 访问权限。”所以我完全不明白这个问题。

编辑:git remote -v 返回:

origin  git@github.com:Aurelien/Repo.git (fetch)
origin  git@github.com:Aurelien/Repo.git (push)

【问题讨论】:

  • 亲爱的马特,多么残酷的回答,但我接受它是因为我需要帮助。我修改我的消息以引用整个文本,即:“git status返回"On the main branch Your branch is in advance of 3 commits upon 'origin/main' (Use "git push" to publish these local commits) Nothing to valid, the copy of your work is clean"
  • 您能否编辑您的问题以将git remote -v 的输出包含为代码块?
  • 您好 bk2204。我添加了输出。

标签: github push


【解决方案1】:

您看到的问题是您正在编写git push README.mdgit push 采用远程名称或 URL,因此您要求 Git 做的是推送到名为 README.md 的本地存储库。但是,因为这是一个文件,而不是 Git 存储库,所以它不起作用。

当你要推送的时候,写git push origin,或者,假设你要推送的分支叫做maingit push origin main。请注意,这将推送您分支的整个历史记录,而不仅仅是一个文件。 Git 没有提供只推送一个文件的方法。相反,它会推送一个提交和导致它的历史记录。

【讨论】:

  • 非常感谢您的友好回答。我将把这个主题重命名为“新手 GitHub 问题”。我在 SSH 上浪费了时间,而这不是 SSH 问题。非常感谢!
  • 您不太可能是唯一这样做的人,因此希望您提出这个问题后,其他人也会受益。
猜你喜欢
  • 2017-12-06
  • 1970-01-01
  • 2018-10-14
  • 2022-01-19
  • 1970-01-01
  • 2020-02-05
  • 2021-02-02
  • 2014-01-23
  • 1970-01-01
相关资源
最近更新 更多