git missing work tree

╄→尐↘猪︶ㄣ 提交于 2019-12-04 17:40:13

You've created a bare git repository (which does not by itself have a working tree). A bare git repository is the recommended way to go when you want to push changes.

And from your question, I understand that you have some sort of server setup, and everytime you do a git push, you want the files on the server to be updated to reflect the newly pushed changes.

Yes it is do-able, but you need to separate the bare repo and work-tree. The work-tree location should correspond to the location where your files need to be deployed on the server. Let's just assume it is /foor/bar. By setting up a post-receive hook, you can deploy the new files to this worktree location, after every push automatically.

These are the steps for this setup:

  1. Create the work-tree directory if it does not exist already.

    mkdir -p /foo/bar
    
  2. Create the following script and copy it in as bare-repo's hooks/post-receive

    #! /bin/sh
    GIT_WORK_TREE=/foo/bar git checkout -f
    
  3. Mark this script as executable:

    chmod +x hooks/post-receive
    

That's all that will be required. Now try a git push and your new changes will be automatically deployed onto /foo/bar location.

A note of caution: git checkout -f clobbers all local changes in any of the tracked files and any such changes in /foo/bar will be lost on a new checkout -f. Any files that are not tracked in git but created/generated under /foo/bar, should not be affected.

Also I would suggest to get rid of the changes you've made in the .git/config, especially for receive.denyCurrentBranch.

Your config should look like this IMO:

[core]
    repositoryformatversion = 0
    filemode = true
    bare = true
    logallrefupdates = true
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!