Why am I getting the message, “fatal: This operation must be run in a work tree?”

前端 未结 15 918
野趣味
野趣味 2020-11-27 12:33

Just installed git on Windows. I set the GIT_DIR variable to be c:\\git\\ and verified that this environment variable is maintained by cygwin (i.e. echo $GIT_DIR is what it

15条回答
  •  臣服心动
    2020-11-27 13:11

    Create a bare GIT repository

    A small rant: git is unable to create a normal bare repository by itself. Stupid git indeed.

    To be precise, it is not possible to clone empty repositories. So an empty repository is a useless repository. Indeed, you normally create an empty repository and immediately fill it:

    git init
    git add .
    

    However, git add is not possible when you create a bare repository:

    git --bare init
    git add .
    

    gives an error "fatal: This operation must be run in a work tree".

    You can't check it out either:

    Initialized empty Git repository in /home/user/myrepos/.git/
    fatal: http://repository.example.org/projects/myrepos.git/info/refs not found: did you run git update-server-info on the server?
    
    git --bare init
    git update-server-info # this creates the info/refs file
    chown -R : . # make sure others can update the repository
    

    The solution is to create another repository elsewhere, add a file in that repository and, push it to the bare repository.

    mkdir temp; cd temp
    git init
    touch .gitignore
    git add .gitignore
    git commit -m "Initial commit"
    git push (url or path of bare repository) master
    cd ..; rm -rf temp
    

    hope this can help u

提交回复
热议问题