How can I commit specific directory to a different than a working branch on git?

后端 未结 1 1750
独厮守ぢ
独厮守ぢ 2020-12-19 16:25

I have a simple static website, based on HTML 5 boilerplate and the whole thing is in a github repository. The project structure is something like this

build         


        
相关标签:
1条回答
  • 2020-12-19 16:43

    Since .gitignore is versioned as well, just don't put the publish/ directory in the gh-pages branch's .gitignore file. Then, you can just do something like this:

    ORIG_HEAD="$(git name-rev --name-only HEAD)" git checkout gh-pages && mv publish/* . && git commit -am "automatic update" && git checkout "$ORIG_HEAD"
    

    It does get tricky since you're wanting to do things in the root directory rather than a subdirectory. Another option would be to simply maintain a separate clone of the same repository in a different directory, that is always on the gh-pages branch. You could have your script just write the files to there instead of to publish/ and then just commit in that clone.

    0 讨论(0)
提交回复
热议问题