我在远程linux盒子上有一个git repo,在windows机器上有另一个repo。
我想:
这就是我的所作所为:
#currently on master branch
git checkout -b remote_trunk
#currently on remote_trunk branch
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'
答案 0 :(得分:2)
默认情况下,git将禁止推送到非裸存储库。
当您推送到远程服务器时,您正在更新其分支引用,如果您在远程repo的工作目录中进行了更改,这可能会导致一些混淆。您可以通过以下方式避免这种混淆:
git help init
和--bare
选项。remote_trunk
,它就会发出警告,它会允许推送。所以在远程仓库上,你可以检查一个不同的分支(例如,在你的情况下git checkout master
)或检查一个分离状态(git checkout --detached
),同时你从本地仓库进行git推送,然后在推送之后,您可以在远程存储库上git checkout remote_trunk
,而不会无声地破坏您的索引。短篇小说:避免推送到非裸存储库 - 更喜欢git pull
将更改合并到其中。如果要将git推送到公共区域,请使用git init --bare
答案 1 :(得分:1)
看起来你的远程存储库不是一个裸存储库,它需要。创建时,请使用:
git init --bare