因为我创建了一个共享存储库文件夹,路径为://web1/www 在另一台电脑上,我创建了一个文件夹,然后打开了 bash,我这样做了:
$ git clone //web1/www
然后在新创建的 repo 文件夹中:
$ git status
# On branch master
nothing to commit, working directory clean
我添加了一个文件,然后:
$ git add .
$ git commit -m 'new file added'
$ git push origin master
但是,我收到以下错误,我现在该怎么办?
s.ali@WEB2 /d/ketab projects/www (master)
$ git push origin master
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 257 bytes, done.
Total 2 (delta 1), reused 0 (delta 0)
remote: error: refusing to update checked out branch: refs/heads/master
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 inconsist
ent
remote: error: with what you pushed, and will require 'git reset --hard' to matc
h
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'.
P.S:我在 Windows 7 本地网络上,使用域而不是工作组
最佳答案
这是因为您的源是一个完整的存储库。
如果你想推送到一个仓库,它必须是一个裸仓库(没有工作树)
创建存储库时使用 --bare 标志
git init --bare
push 命令只更新内部 git 文件,而不是工作目录。因此,本质上,如果您推送到完整的存储库,HEAD(工作目录中 checkout 的文件)实际上将位于您刚刚推送的前沿提交之后。因此 git 开发人员决定不允许这样做。
关于git - 为什么我无法推送新克隆的存储库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14217406/