Search code examples
gitgitignore

Git command within ignored folders - can it truly ignore that it is within a git repo?


I'm having a git repo setup in my main users directory in order to sync configuration among my computers like so:

/Users/myusername/.versionedConfigFile
/Users/myusername/myOtherFolders <-- to be igored
/Users/myusername/projects/somerepo/.git <-- to be igored

Besides these configuration file I want everything else to be ignored in my git repo, which is why my .gitignore looks like this:

   *
   !.gitignore
   !.versionedConfigFile

While .gitignore allows me to exclude all my other files from tracking, I can still see that I'm in a git repository when I cd into "myOtherFolders" for example and running git commands like "git status". I would prefer to see "not a git repository" here to not get confused when working with other git repos in my directory tree (which still works of course).

Is there a way to "truly" exclude the folders from the .git repository?


Solution

  • Another option would be to:

    • have your Git repository in a separate location, with in it your .versionedConfigFile
    • have a symlink in /Users/myusername/.versionedConfigFile to that separate repository.

    That way, you don't have to ignore everything, and you can have other repositories in /Users/myusername/.