Git 推送到远程分支失败
我在远程linux机器上有一个git repo,在windows机器上有另一个repo 我想:Git 推送到远程分支失败,git,Git,我在远程linux机器上有一个git repo,在windows机器上有另一个repo 我想: 从linux计算机签出分支 本地操作(从我的windows计算机) 本地提交 然后推到远程分支 我就是这么做的: 在Linux上(远程) 在Windows上(本地) 结果 看起来您的远程存储库不是一个空的存储库,它必须是空的。创建时,请使用: git init --bare 默认情况下,git将不允许推送到非裸存储库 当您推送到远程服务器时,您正在更新它的分支引用,如果您在远程repo的工作目录
- 从linux计算机签出分支
- 本地操作(从我的windows计算机)
- 本地提交
- 然后推到远程分支
看起来您的远程存储库不是一个空的存储库,它必须是空的。创建时,请使用:
git init --bare
默认情况下,git将不允许推送到非裸存储库 当您推送到远程服务器时,您正在更新它的分支引用,如果您在远程repo的工作目录中有更改,这可能会导致一些混乱。您可以通过以下方式避免这种混淆:
- 您的最佳选择是建立一个单独的裸存储库,并从两个开发区域推送到共享回购。选中
和git help init
选项--bare
- 仅在两个repo之间执行git fetch/pull(不执行git推送)
- 如警告所示,您可以设置'receive.denyCurrentBranch'变量。这将允许推送,但不是推荐的选项,除非您知道自己在做什么并且非常小心
- 从警告中听起来,只要远程Linux存储库当前没有签出
,它就会允许推送。因此,在远程repo上,当您从本地repo执行git推送时,您可以签出不同的分支(例如,在您的情况下,remote\u trunk
)或签出分离状态(git checkout master
),然后,在按下按钮之后,您可以在远程存储库上git checkout--detached
,而无需它默默地破坏您的索引git checkout remote_trunk
短篇故事:避免推送到非裸存储库——更喜欢
git-pull
将更改合并到存储库中。如果您想将git推送到公共区域,请使用git init--bare设置一个裸机存储库,谢谢您的回复。。。。但我希望能够同时处理两种回购协议……这不可能吗?如果我将远程repo设置为裸机,那么我将无法正确处理它?不,但是您可以按照@jkyako的建议执行,或者在与裸机repo相同的主机上创建第二个克隆。我添加了receive.denyCurrentBranch选项,并使用-f选项推送,这很有效。但在远端,我需要隐藏起来才能看到变化!push-f会替换上一次提交,但会将旧文件保留在当前目录中……顺便说一句,你不必对每个问题都发表相同的评论。我们都会看到的。:)我不会再那样做了:)谢谢你的回复。。。。但我希望能够同时处理两种回购协议……这不可能吗?如果我把远程回购暴露在外,那么我就不能处理它了,对吗?对。您可以尝试在远程Linux repo上执行git checkout master
,这段时间您希望从Windows repo中推送(或者至少,这是我从错误消息中得到的)。或者,您可以在Linux repo上设置“receive.denyCurrentBranch”以允许推送,但我不愿这样做。我最喜欢Don的建议,即创建第三个(裸)repo,并将其用作两个开发区域的清算所。我添加了receive.denyCurrentBranch选项,并使用-f选项推送,这是可行的。但在远端,我需要隐藏起来才能看到变化!push-f取代了上一次提交,但将旧文件保留在当前目录中……更简短的说法是:避免推送到非裸存储库——更喜欢git pull
将更改合并到它们中。如果您想git push
到公共区域,请使用git init--bare
设置一个裸机存储库。在Cupcake的参考中,请参阅Charles Bailey发布的答案和Nowhere Man答案中的“尸检”以获得良好的解释。我添加了receive.denyCurrentBranch选项,并使用-f选项推送,这很有效。但在远端,我需要隐藏起来才能看到变化!它表示push-f将替换上一次提交,但将旧文件保留在当前目录中。。。
git fetch origin
git checkout remote_trunk
#currently on remote_trunk branch
# then I modify some files
git commit -a -m"I modified some files"
git push origin remote_trunk
Counting objects: 9, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 432 bytes | 0 bytes/s, done.
Total 5 (delta 4), reused 0 (delta 0)
remote: error: refusing to update checked out branch: refs/heads/remote_trunk
remote: error: By default, updating the current branch in a non-bare repository
remote: error: is denied, because it will make the index and work tree inconsistent
remote: error: with what you pushed, and will require 'git reset --hard' to match
remote: error: the work tree to HEAD.
remote: error:
remote: error: You can set 'receive.denyCurrentBranch' configuration variable to
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into
remote: error: its current branch; however, this is not recommended unless you
remote: error: arranged to update its work tree to match what you pushed in some
remote: error: other way.
remote: error:
remote: error: To squelch this message and still keep the default behaviour, set
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
To Z:/shadow.git/ets/src/trunk/src
! [remote rejected] remote_trunk -> remote_trunk (branch is currently checked out)
error: failed to push some refs to 'Z:/shadow.git/ets/src/trunk/src'
git init --bare