我正在学习git。我使用Git for Windows。
为什么我在git push origin master
命令工作时出错?
我已编写脚本(BAT文件)来显示此问题:
:: script.bat
::======================
:: Git repositories host
set host=d:/sandbox
:: Virtual disk name
set disk=v:
subst %disk% %host%
cd /D %disk%/
:: create some "remote" repository
set origin=v:\server
mkdir %origin%
set git="C:\Program Files\Git\bin\git.exe"
call %git% init %origin%
echo aaa > "%origin%/a.txt"
echo bbb > "%origin%/b.txt"
echo ccc > "%origin%/c.txt"
cd %origin%
call %git% add "*"
call %git% commit -m "Initialized"
:: clone our "remote" repository
set client1=%disk%\client-1
call %git% clone "%origin%" "%client1%"
cd "%client1%"
call %git% remote -v
echo ddd > "%client1%/d.txt"
call %git% add "./d.txt"
call %git% commit -m "./d.txt file added"
call %git% status
:: here is the problem...
call %git% push origin master
subst /D %disk%
我得到了这样的输出:
C:\Users\bushm>D:\sandbox\script.bat
C:\Users\bushm>set host=d:/sandbox
C:\Users\bushm>set disk=v:
C:\Users\bushm>subst v: d:/sandbox
C:\Users\bushm>cd /D v:/
v:\>set origin=v:\server
v:\>mkdir v:\server
v:\>set git="C:\Program Files\Git\bin\git.exe"
v:\>call "C:\Program Files\Git\bin\git.exe" init v:\server
Initialized empty Git repository in v:/server/.git/
v:\>echo aaa 1>"v:\server/a.txt"
v:\>echo bbb 1>"v:\server/b.txt"
v:\>echo ccc 1>"v:\server/c.txt"
v:\>cd v:\server
v:\server>call "C:\Program Files\Git\bin\git.exe" add "*"
v:\server>call "C:\Program Files\Git\bin\git.exe" commit -m "Initialized"
[master (root-commit) 49f7952] Initialized
3 files changed, 3 insertions(+)
create mode 100644 a.txt
create mode 100644 b.txt
create mode 100644 c.txt
v:\server>set client1=v:\client-1
v:\server>cd "v:\"
v:\>call "C:\Program Files\Git\bin\git.exe" clone "v:\server" "v:\client-1"
Cloning into 'v:\client-1'...
done.
v:\>cd "v:\client-1"
v:\client-1>call "C:\Program Files\Git\bin\git.exe" remote -v
origin v:\server (fetch)
origin v:\server (push)
v:\client-1>echo ddd 1>"v:\client-1/d.txt"
v:\client-1>call "C:\Program Files\Git\bin\git.exe" add "./d.txt"
v:\client-1>call "C:\Program Files\Git\bin\git.exe" commit -m "./d.txt file adde
d"
[master b6a43f1] ./d.txt file added
1 file changed, 1 insertion(+)
create mode 100644 d.txt
v:\client-1>call "C:\Program Files\Git\bin\git.exe" status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
nothing to commit, working directory clean
v:\client-1>call "C:\Program Files\Git\bin\git.exe" push origin master
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 278 bytes | 0 bytes/s, done.
Total 3 (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'.
To v:\server
! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to 'v:\server'
v:\client-1>subst /D v:
v:\client-1>
为什么我会收到这些错误?
答案 0 :(得分:0)
这是因为您的服务器不是一个裸仓库,而且您已经检查了主分支。