keflavich
keflavich

Reputation: 19215

Ignore .git in parent directories for git status, branch, etc?

Is it possible to prevent git from searching parent directories for .git folders? I have a .git in my user root directory to back up / branch my config files, but that has the undesired consequence that all subdirectories that don't have their own .git folders appear to be children of the user root.

Upvotes: 8

Views: 723

Answers (3)

user1142217
user1142217

Reputation:

Try putting this in your .bashrc:

export GIT_CEILING_DIRECTORIES='/home/keflavich'

If you're in a subdirectory of /home/keflavich, the .git stuff in /home/keflavich will be invisible. But if you're in /home/keflavich, it will be visible, which I think is what you want.

Upvotes: 11

Nevik Rehnel
Nevik Rehnel

Reputation: 51945

You can use .gitignore to ignore all subfolders by using the line

/*/

(that is, forward slash, asterisk, forward slash) the first slash means it refers to the root of the repo, the asterisk means "any name", the trailing slash means "only directories".

Any directories that you do want to track, you can add with git add -f.

See also the man pages of .gitignore and git add.

Upvotes: 0

poke
poke

Reputation: 387707

You can add a .gitignore that ignores everything (i.e. its contents is just *). That way, nothing will be tracked or recognized by Git unless you explicitely tell Git to do it, i.e. add a file to the repository using git add -f filename.

Upvotes: 1

Related Questions