3

I have a git repository of my dot-files in my home directory. Every time I use a git command (e.g. git log) in a subdirectory, which doesn't have it's own repo, I'm getting the log of the dot files repo, e.g.

/home/dimid     $ cd foo
/home/dimid/foo $ git status

... log of ~/.git

However, I would like to confine my dot-repository only to files and directories that begin with a dot (e.g. .vim), such that when I'm in ~/foo and ~/foo/.git doesn't exist git log will output the usual

fatal: Not a git repository (or any of the parent directories): .git

even though that the parent directory ~ contains a .git folder.

I thought about aliasing git and add an exception, is there a more elegant way?

dimid
  • 7,285
  • 1
  • 46
  • 85
  • I'm afraid that's quite difficult to obtain; if not impossible. Git is made to go up directories to check if the current directory is part of a git repo; and since your home directory is one... – Chris Maes Nov 06 '15 at 13:50
  • Rather than searching for how to make Git ignore subdirectories, perhaps you should be searching for how to properly keep files like your .vimrc in source control. – tom Nov 06 '15 at 15:35
  • @tom I'd love to hear suggestions – dimid Nov 09 '15 at 13:47
  • @dimid here's someone's response to the exact same root problem http://stackoverflow.com/a/18197818/1394473 – tom Nov 10 '15 at 17:33

1 Answers1

3

I don't know any way of doing that; since Git always moves up your directory tree until he finds a .git directory. Now since your /home directory is a git repository; all sub-directories will always find that .git directory in your /home folder.

I can see one work-around, but it isn't very clean...

  • create a subdirectory in your home (or elsewhere); where you will initialize your git repository (eg "/home/user/configfiles/")
  • now create hardlinks between your configfiles you want to keep in your git repository and the ones on your system (eg "ln ~/.config ./") (note you need to use hardlinks; otherwise git will only version the path where the symbolic link is pointing to)

This way your home directory will not be a git repository anymore; and the problem is avoided...

Chris Maes
  • 35,025
  • 12
  • 111
  • 136
  • Thanks, but `~` has some submodules (like `.vim/bundle`) so I'd rather not having to track them dynamically and add hardlinks – dimid Nov 07 '15 at 17:32
  • I know it isn't the most beautiful solution... But you had to do 'git add' for each file anyway? – Chris Maes Nov 07 '15 at 18:58
  • I agree that this solution isn't very beautifull (as I said in the answer). It does have quite some flaws; but it's the best I could come up with... – Chris Maes Nov 09 '15 at 07:40
  • Thanks, I upvoted your answer. If no better alternative comes up, I'll accept it or try the alias trick. – dimid Nov 09 '15 at 12:51
  • 1
    tx. It is a valid question; I'd be interested too if I hear any other suggestions :) – Chris Maes Nov 09 '15 at 13:07