Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 883
Kenneth McDonald Avatar asked Jun 30 '11 18:06

Kenneth McDonald


People also ask

What happens to untracked files in git?

Untracked basically means that Git sees a file you didn't have in the previous snapshot (commit), and which hasn't yet been staged; Git won't start including it in your commit snapshots until you explicitly tell it to do so.

What happens to untracked files?

Untracked files are the ones still not versioned—”tracked”—by Git. This is the state of new files you add to your repository. That basically means Git is aware the file exists, but still hasn't saved it in its internal database.

What does untracked mean in github?

Untracked files are files that have been created within your repo's working directory but have not yet been added to the repository's tracking index using the git add command.

What happens to untracked files when switching branches?

Take away: changing branches does not touch/change/remove untracked or checked in files. Remember that the working directory and index are not 'cleared' before the branch content is loaded into it!


1 Answers

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

like image 147
Tekkub Avatar answered Nov 14 '22 21:11

Tekkub