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:

  • Reset to the very first commit in Git?
  • Add gray area in markdown
  • Is it possible to use komodo edit as git core.editor (i.e. without forking)?
  • Git reset --hard and a remote repository
  • gitignore - allow folder creation but ignore all files inside - can we do it with exclamation mark (!)?
  • What do line colors in git log --graph mean?
  • // 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.

  • How do I pass an absolute path to the adb command via git bash for windows?
  • How long should I keep my fork projects on github?
  • Git status picking up parent folder's files
  • Alias branch for last release in Git
  • What to do with branch after merge
  • Gradle: how to clone a git repo in a task?
  • 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”.

    It’s because git pages is for web files (e.g. .html) instead of source files. So what those instructions are telling you is how to create a totally clean branch (which in normal behavior you don’t want to do) without all the source files, for hosting only web-serve-able-on-github files, html, css, javascript.

    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
    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

    Git Baby is a git and github fan, let's start git clone.