Why is it necessary to lose untracked files when you set up github pages?
Github has a feature where you can put up HTML pages. (Details here).
Anyway, I recently used this to put up the aforementioned page. The basics of the instructions to do so are:
// In order to create a new root branch, first ensure that your working directory is clean by committing or stashing any changes. The following operation will lose any uncommitted files! You might want to run this in a fresh clone of your repo. $ cd /path/to/fancypants $ git symbolic-ref HEAD refs/heads/gh-pages $ rm .git/index $ git clean -fdx // After running this you’ll have an empty working directory (don’t worry, your main repo is still on the master branch). Now you can create some content in this branch and push it to GitHub. For example: $ echo "My GitHub Page" > index.html $ git add . $ git commit -a -m "First pages commit" $ git push origin gh-pages
So that went fine; as advertised, my untracked files were wiped but I’d made a copy of the dir and just moved back what was necessary. Switching back and forth between branches (I use SmartGit) doesn’t seem to wipe untracked files.
However, I’m interested in expanding my very basic knowledge of Git, and am wondering why it was necessary to wipe untracked files the first time gh-pages was set up. I would have thought it would be possible to set up the gh-pages branch, add and commit the html file to it and push it, all without affecting untracked files. And then just switch back to the original branch.
4 Solutions collect form web for “Why is it necessary to lose untracked files when you set up github pages?”
Best bet, make a new clone and do it in that. If you absolutely must do it in the repo you’re currently working in, try
git checkout --orphan gh-pages
You can create the
gh-pages branch without the root directory if you drop the
git clean command and do
git add <files> instead of
git add .. This would be the workflow:
cd /path/to/fancypants git symbolic-ref HEAD refs/heads/gh-pages rm .git/index echo "My GitHub Page" > index.html git add index.html git commit -a -m "First pages commit" git push origin gh-pages
I think they express the directions the way they do for the sake of simplicity and avoiding “fanciness”.
So if you want clean, you can do it that way. If you’re okay with totally dirty, you can probably try simply creating a branch (git branch gh-pages) and pushing that. I think that I’ve done that before and it worked just fine, especially when I was dealing with just web-servable stuff in the repository to begin with.
The Problem was the
git clean removes any untracked file from the current working tree.
You could set up
.gitignore files for the untracked files and leave the
-x flag away. You should have a look at the manpage for
git-clean. If you don’t have a unix system: http://linux.die.net/man/1/git-clean