What Is The Best Way To Move The Context Of A Git Repo?

- 1 answer

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


as the root rather than what I'm currently pushing from


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.



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:

  1. Make changes to repoA (e.g. write a new post)
  2. Commit changes on repoA
  3. Run jekyll to build your website (generates _site)
  4. (Optionally) push the changes somewhere, usually private
  5. Delete all files and folders on repoB
  6. Move all contents from repoA\_site to repoB\
  7. Commit changes on repoB
  8. 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.