【问题标题】:Reconnect git local to GitHub remote without losing a new local branch and commits将本地 git 重新连接到 GitHub 远程,而不会丢失新的本地分支和提交
【发布时间】:2021-06-24 04:10:58
【问题描述】:

在一些帮助下,我设法从 fatal: not a git repository (or any of the parent directories): .git 问题中恢复了本地 git 项目...Why does git not recognise my local repository?

但是现在我的本地 git 在一个新的本地分支上(在 GitHub 远程上不存在)并且与现有的远程源断开连接。

  • git remote -v 不返回任何内容

如何重新连接本地 git 并将其推送到现有的 GitHub 远程,而不会丢失新的本地分支及其提交?

【问题讨论】:

  • is disconnected from the existing remote origin 你能澄清一下这是什么意思吗,例如通过在您尝试git checkout my-branch; git push 时将命令和输出添加到问题中?
  • 已添加git remote -v 感谢@AD7six,我会努力养成这样的习惯。

标签: git github git-remote


【解决方案1】:

添加遥控器:

git remote add origin http://github.com/user/repo.git

然后推送更改。

【讨论】:

  • 好的,这比我想象的要简单,谢谢!但是有一个问题,这会自动跟踪所有现有的分支,还是我需要为每个分支使用git push -u origin branch
  • 想通了,所有的分支都需要重新设置以跟踪相关的远程分支,每个分支使用git push -u origin branch
  • @Dan:实际上每个分支只需要一个git branch --set-upstream-togit push 选项 -u 表示:成功推送后,也运行 git branch --set-upstream-to。请注意,每个分支要么没有上游,要么有一个上游,因此如果某些分支已经有上游集(尽管在这种特殊情况下没有),如果您选择不同的上游,这可能会更改上游这次。有关上游的更多信息,请参阅我对 this question 的回答。
猜你喜欢
  • 2018-07-21
  • 1970-01-01
  • 1970-01-01
  • 2016-06-12
  • 2022-01-05
  • 2015-07-24
  • 1970-01-01
  • 2020-07-07
  • 2021-11-02
相关资源
最近更新 更多