git push origin master 报错

2014-09-10 11:48:45 +08:00
 yakczh
先建立orgin
mkdir E:\g\gitsrc
cd E:\g\gitsrc
git init
echo "some" > some.txt
git add some.txt
git commit -m'some '


再clone到F:\下的gitwork
git clone E:\g\gitsrc gitwork
echo "apend data " >> some.txt
git commit -m'append'
git push origin master
结果报错
Counting objects: 5, done.
Writing objects: 100% (3/3), 250 bytes | 0 bytes/s, done.
Total 3 (delta 0), 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 inconsiste
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 e:\g\gitsrc
! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to 'e:\g\gitsrc'
上面的命令是哪一步出错了?
3642 次点击
所在节点    问与答
9 条回复
lemontv
2014-09-10 12:49:56 +08:00
remote: error: By default, updating the current branch in a non-bare repository
git init --bare
aa65535
2014-09-10 12:58:15 +08:00
git init 初始化生成的属于 working repository (工作仓库);
应该使用git init --bare 来初始化成 bare repository,这样才能接受 push。
你这样干,报错是当然了。
yakczh
2014-09-10 13:07:45 +08:00
@lemontv 这样可以 在f:\gitwork下 push origin master 但是在 E:\g\gitsrc 下看不到文件变动 是不是在E:\g\gitsrc 下还要操作才能看到更新?
yakczh
2014-09-10 16:30:04 +08:00
@aa65535 git --bare init 这样生成的项目 里面的目录结构是 branches config description HEAD hooks info objects refs
从本地F:\gitwork 下可git push origin master
但在E:\g\gitsrc 里面怎么得到更新?
aa65535
2014-09-10 17:23:53 +08:00
@yakczh bare repository 是不可以直接修改的,通过 clone 后的 working repository 修改,然后 push。
yakczh
2014-09-10 17:30:25 +08:00
@aa65535 怎么样在bare repository看修改的变动? 是不是要看到 bare repository 里面的修改变动, 还需要再clone出另一个 working repository 来?
aa65535
2014-09-10 18:15:06 +08:00
@yakczh bare repository 中可以使用 git log 的。
可以这样理解:
bare repository相当于server
working repository相当于client
jy01264313
2014-09-10 18:25:18 +08:00
git remote add origin url 需要添加远程的 repo 吧
lemontv
2014-09-10 23:05:43 +08:00
@yakczh
建议你完整的读一遍 http://git-scm.com/book/zh

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/132670

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX