Git - How to auto push changes in a directory to another branch

前端 未结 2 1446
无人及你
无人及你 2020-12-06 07:25

Complete question rewrite

So I thought I was explaining this question very simply and direct but it seems I oversimplified to much, so here is a

2条回答
  •  半阙折子戏
    2020-12-06 07:59

    What's the problem with the hook script you wrote ? What were the contents of the branch gh-pages when you created it?

    I had created an empty branch gh-pages with below command:

    git checkout --orphan gh-pages
    git rm -rf .
    touch README.txt
    git add README.txt
    git commit -m "Initial commit"
    git push -u origin gh-pages
    

    Then I ran below script as a part of post-receive hook and it worked for me.

    #!/bin/bash
    branch=`git rev-parse --abbrev-ref HEAD` 
    if [ "master" == "$branch" ]; then
        git fetch && git checkout gh-pages
        git checkout master -- gh-pages
        git add -A
        git commit -m "Updating project website from 'master' branch."
        git push -u origin gh-pages
    fi
    done
    

提交回复
热议问题