Git push error '[remote rejected] master -> master (branch is currently checked out)'

前端 未结 30 2221
半阙折子戏
半阙折子戏 2020-11-22 00:07

Yesterday, I posted a question on how to clone a Git repository from one of my machines to another, How can I \'git clone\' from another machine?.

I am now

30条回答
  •  太阳男子
    2020-11-22 00:26

    git config --local receive.denyCurrentBranch updateInstead

    https://github.com/git/git/blob/v2.3.0/Documentation/config.txt#L2155

    Use that on the server repository, and it also updates the working tree if no untracked overwrite would happen.

    It was added in Git 2.3 as mentioned by VonC in the comments.

    I've compiled Git 2.3 and gave it a try. Sample usage:

    git init server
    cd server
    touch a
    git add .
    git commit -m 0
    git config --local receive.denyCurrentBranch updateInstead
    
    cd ..
    git clone server local
    cd local
    touch b
    git add .
    git commit -m 1
    git push origin master:master
    
    cd ../server
    ls
    

    Output:

    a
    b
    

    Yay, b got pushed!

提交回复
热议问题