1

I'm versioning my $HOME with git, but with an differently-named repository directory so that my prompt doesn't always show git information.

I have setup an alias for when I want to use git on my $HOME:

alias gith='git --git-dir=/home/ravi/.githome --work-tree=/home/ravi'

The repository directory .githome itself shouldn't be showing up in a gith status, but it is:

~$ git --git-dir=/home/ravi/.githome --work-tree=/home/ravi status -s
 M .dotfiles
 M .githome/COMMIT_EDITMSG
 M .githome/index
 M .githome/index.lock
 M .githome/logs/HEAD
 M .githome/logs/refs/heads/master
 M .githome/refs/heads/master
 M .local/share/fzf
 M bin
 M lib
 M prj/sample_app

I'm trying to ignore the directory .githome as follows:

~$ grep .githome .gitignore
/.githome/
~$ cat .githome/.gitignore 
*

Questions:

  1. Why aren't my two exclude files working?
  2. Why do I need to explictly exclude the repository directory anyway?
Tom Hale
  • 40,825
  • 36
  • 187
  • 242
  • 1
    This sounds like maybe you initialized your Git repository in the wrong place, or there were folders inside which should not have been there. As to why `.gitignore` might not be working, if you already committed these folders/files to your repository, then `.gitignore` won't work after the fact. – Tim Biegeleisen Nov 30 '16 at 09:59

2 Answers2

3

Make sure that you haven't committed githome already because gitignore cannot delete files from a repository.

git rm -rf --cached .
git add .

Run this. It will make your repository work again by clearing everything and pulling it with respect to your gitignore file.

kninjaboi
  • 201
  • 1
  • 12
  • 1
    @TomHale Thanks! :D I've been using it for so long and I decided it's time to start answering some questions. – kninjaboi Dec 01 '16 at 03:26
  • It's a great community dedicated to the advancement of human knowledge. Thanks playing your part :) – Tom Hale Dec 01 '16 at 04:05
1

It turned out that .githome had been already added in a previous commit.

Based on @Tim's comment and @KingAlandyDy's answer, I did the following:

gith rm -r --cached .githome/
Tom Hale
  • 40,825
  • 36
  • 187
  • 242
  • 2
    Watch out for "going back in time" (checking out old commits). Once the files are back in the index, as they will be because you checked out an old commit, and you then ask to go "forward in time" (returning to your usual "master"), Git will, in effect, say: "oh, I see I have these files in the current back-in-time commit, and not in the new commit, so I should just remove them from the work-tree now." If you can afford to re-hash all the commits in the repository, see the filter-branch and BFG answers to http://stackoverflow.com/q/307828/1256452 – torek Nov 30 '16 at 14:18