【问题标题】:Pushing to a different remote repository推送到不同的远程存储库
【发布时间】:2019-09-18 13:16:59
【问题描述】:

假设我有一个本地存储库 A,并且我可以访问远程存储库 B。这些存储库完全不同!我想将所有文件/提交等从 A 推送到 B 存储库。 所以我做了以下 git 命令:

  1. git remote add origin <my remote git url>
  2. git push origin master

我收到以下错误:

hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.

问题的原因是我不想执行 git pull 命令,因为 B 存储库占用了大量空间(数千兆字节!)而 A 存储库需要几千字节。

有没有什么方法可以推而不拉?

【问题讨论】:

  • 推送到远程不存在的分支。 (例如,在远程创建一个新分支)
  • AFAIK 你不能“将文件从 A 推送到 B”。提交是所有文件的快照,提交是“推送和拉取”的内容。 - 但是这个问题似乎不是在问那个

标签: git push git-remote


【解决方案1】:

在远程创建一个新分支:

git push origin master:my-branch

然后,在远程,您可能希望将您的工作添加到主分支。一种方法是:

git checkout my-branch
git rebase master
git checkout master
git merge my-branch

【讨论】:

  • 谢谢!这就是我需要的
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-06-11
  • 2018-06-24
  • 2010-10-25
  • 1970-01-01
  • 1970-01-01
  • 2019-12-11
相关资源
最近更新 更多