How can I commit specific directory to a different than a working branch on git?
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 css img js publish # this directory isn't in source control! ... index.html & other files
Basically what I do is run a build script (from HTML 5 boilerplate) that compiles all the HTML/CSS/JS into the
publish directory, which isn’t in the git repository.
Now what I want to do, is make use of GitHub pages and be able to use the
publish directory output as a GitHub page.
The way GitHub pages work, is that you create a clean separate branch named
gh-pages, which will contain the final content. What I want to do, is to be able to on demand commit the current
publish directory into the
gh-pages branch, but I also want to keep it in the main
.gitignore file so it won’t get pushed into the source repository.
I want to do this to kinda preview the current state of the project.
in short: I need to commit one directory to a separate branch, so it’s root will be the same as contents of that one directory.
publish/css will become just
css on the
One Solution collect form web for “How can I commit specific directory to a different than a working branch on git?”
.gitignore is versioned as well, just don’t put the
publish/ directory in the
.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.