views:

328

answers:

5

I have my dot files in Github publicly.

This means that I have only a few files at my Home shared with others.

The disadvantage of sharing, for instance, .bashrc with others is that I need to be careful not adding confidential data to Github.

I run

git status

I get a long list of untracked files.

I found out that apparently the only way to get rid of them them is by running

git clean -df

This would remove my private files which I do not want to.

How can you remove my private files from Git's status without removing my private files at my Home?

+7  A: 

Create a .gitignore file in the root directory of the git.

Here's an example .gitignore file:

.*

Bin/*

Obj/*

/.vcproj.*.user

*.ncb

*.suo

EDIT: Git Cheat Sheet.

kitchen
+1  A: 

You want to add them to your gitignore file.

For example, you could create a file named .gitignore in your home directory and list the files that you don't want tracked (like: .bashrc).

Aaron Maenpaa
+1  A: 

Create a file called .gitignore in your home folder, then put, one per line, the parameters that you do not want git to see.

So, if you have .bashrc and you do not want git to see it, put .bashrc on one line.

It's important that you have never added .bashrc with git add, because if you did this will not work. You will have to remove the file from the source control and only then it will be ignored by git status.

Rafael
+1  A: 

Or follow the solution I outlined previously in http://stackoverflow.com/questions/1053867/unable-to-work-effectively-with-git-locally/1056801#1056801

Alec the Geek
+3  A: 

You can ask Git to ignore given untracked files using gitignore mechanism:

  • .gitignore file in current directory
  • .gitignore file in top directory of your repository
  • info/exclude file in $GIT_DIR (in .git repository database)
  • set core.excludesFile config variable to e.g. "/home/user/.gitignore"
    (currently Git does not expand environmental variables such as $HOME or '~' in paths)

For your situation it would be probably best to use '.git/info/exclude', because this way name of ignored file would be not visible to others, contrary to the situation where you accidentally commit .gitignore file, or you are forced to have it in repository. Usually .gitignore (versioned and distributed) is about ignoring e.g. generated files, while info/exclude (or code.excludesFile) is about ignoring site-specific files, like backup files of your editor.

Jakub Narębski
Thank you for your answer!
Masi
@Jakub: Assume I have a list of files in /info/exclude. I run `git add .`. Does the command adds also the files to Git which are in /info/exclude?
Masi
@Masi: No, it would not (it is easily to test that "git add ." doesn't add ignored files).
Jakub Narębski