What Is The Best Way To Move The Context Of A Git Repo?
I currently have a git repo for a Jekyll blog that publishes to GitHub Pages. When I set this up initially I initialized git at the root of the blog directory. This means I'm committing and pushing all the Jekyll source files rather than only the static rendered content. Basically, I want to push from
$~/writing/_site/
as the root rather than what I'm currently pushing from
$~/writing/
I would like to start pushing to the remote repo just the static content, leaving all the source files only on my local machine. I've considered creating a local branch and changing things but I don't think that achieves my result. It's not that I'm changing the content itself, but rather pushing a child directory rather than a parent directory.
I assume I could issue
$ git push --force
from the parent directory and then initialize a repo at the child directory and push from it, but that seems like a crude ignorance at play.
I could git-push --force
, copy the Jekyll source to another untracked directory, and then create a branch and git-rm
all the source and git-mv
the content from the child directory into the parent directory but this also feels like oil painting with a piece of bread.
Answer
Assuming that you want to continue to have version control for the source code of your site, to do what you want, you'll need two completely separate Git repositories. One to store the source code, and another one to store the static contents that are generated by Jekyll in the _site
folder.
- repoA - Full Jekyll source code
- repoB - Just the static content
The workflow would be something like this:
- Make changes to repoA (e.g. write a new post)
- Commit changes on repoA
- Run
jekyll
to build your website (generates_site
) - (Optionally) push the changes somewhere, usually private
- Delete all files and folders on repoB
- Move all contents from repoA
\_site
to repoB\
- Commit changes on repoB
- Push changes in repoB to GitHub pages
You'll probably want to automate steps 5
to 8
as they are boring and repetitive. For that there are a myriad of tools you can use, such as Rake, Gulp, Grunt, etc.
If you go with Rake, you may also want to take a look at jekyll-rakefile.
Related Questions
- → Authenticate with a cookie using laravel 5.1 and jwt
- → Finding a specific GitLab tag from PHP
- → React: How to publish page on server using React-starter-kit
- → babel-loader, webpack, ES2015 modules: "Element type is invalid"
- → Create a function-attribute of a function, which is, in its turn, a method of an object literal
- → Model Validation in laravel 5.1 not working
- → GIT fatal: loose object
- → Laravel validation required rule not working
- → Axios array map callback
- → Where does this `webpack://` come from for `webpack-dev-middleware`?
- → error when trying to modify project in laravel forge
- → GitHub Pages and Jekyll content duplication and SEO issues
- → Use Laravel repositories with Datatables