how do I deploy multiple branches to different directories via git push?

前端 未结 4 1187
礼貌的吻别
礼貌的吻别 2020-12-10 17:38

In production, I maintain two sites - beta and release. Each points to a different directory via a soft link (e.g.)

beta_public_html -> /home/scott/myapp/         


        
4条回答
  •  不思量自难忘°
    2020-12-10 18:11

    I use a post-receive hook like this to publish my website, because Git does not touch the working directory when doing a push. The remote repository is a non-bare repository, i.e. it has a working directory.

    if [ -n $GIT_DIR ]; then
        # Current dir is "/.git/", but we need to run reset at "/".
        # Clearing GIT_DIR is needed, or reset will fail with "fatal: Not a git repository: '.'"
        unset GIT_DIR
        cd ..
    fi
    git reset --hard
    

    (BTW, note that I can't seem to push to "myapp-beta.git" - that fails, I have to push to the directory name. I am worried that this is part of the problem, but I don't know what I did wrong here.)

    When creating a bare Git repository (git init --bare) which does not have a working directory, it is a convention to name the directory "something.git". When having a non-bare repository, the repository is actually in the ".git" subdirectory, so the full path is "something/.git". It seems that in either case you can leave out the ".git" part and Git will detect it automatically.

提交回复
热议问题