1

I want to stop tracking certain files in Git that I've added to the .gitignore file.

I used git rm --cached (and also tried git rm -r --cached .) but after running git add ., a git commit --dry-run tells me the files in my gitignore are "to be committed".

The contents of the .gitignore file are:

/source/backup/*
/site/index.php
/site/userscript.user.js

What's wrong with this gitignore?

Things were working just fine when the only line was source/backup/*. As soon as I added the second line, the source/backup/* files are getting committed as well.

Laoujin
  • 9,962
  • 7
  • 42
  • 69

1 Answers1

3

Clear out your index.

git reset

Stop tracking files in your backup folder.

git rm --cached source/backup/

Commit this change by itself.

git commit -m "Removing backup folder from git."

Proceed normally. Ignored files should not accidentally slip in at this point provided your ignore file is setup properly. I'd recommend preceding it with a slash (assuming that folder exists in the root of your repository).

#.gitignore
/source/backup/
/site/index.php

Open up YouTube. Master git. http://youtu.be/ZDR433b0HJY

TheBuzzSaw
  • 8,648
  • 5
  • 39
  • 58
  • After these steps, I still get the backup files after I do a `git add .`. It is the intention that you cannot `git add` gitignored files right? I'll update the original question with the latest gitignore. – Laoujin Apr 02 '13 at 21:42
  • Get rid of that asterisk. I don't know if it causes any harm here, but all my ignore files just refer to the path (as my example indicates in my post), and I know they are working. – TheBuzzSaw Apr 02 '13 at 22:31
  • I missed that you removed the `*`. Removing that one plus adding the initial \ did the trick. Thanks a bunch, been busy with this one for a few hours :). – Laoujin Apr 03 '13 at 00:16
  • I just got around watching the youtube movie: Excellent presentation! Thanks for sharing. Am hardly a 'master' now but at least I have some idea of what I'm doing. – Laoujin Apr 18 '13 at 07:32
  • @Laoujin Yeah, it's a great video. I recommend it to anyone I run into working with git. – TheBuzzSaw Apr 18 '13 at 18:49