0

I was doing an initial commit to my remote repository and git uploaded the file wp-config.php even though it was listed in the .gitignore file

.DS_Store
.sass-cache/*
.vagrant/
wp-config.php
Vagrantfile

/filer

What am I doing wrong, I can't have that file in the remote repository. How can I prevent it from uploading it?

Leff
  • 1,968
  • 24
  • 97
  • 201
  • `.gitignore` is read only by `git add`. If you added the files to the repo **before** writing their names in `.gitignore` then, well, they were already added to the repo. You can `git rm --cached wp-config.php` then `git commit --amend` to remove them from the most recent commit (assuming it is the only one you did until now). – axiac May 26 '17 at 14:23
  • 1
    From what I understand, if that file were in your `.gitignore` then Git should have treated the file as being untracked. Are you saying you were able to `git add` this file? – Tim Biegeleisen May 26 '17 at 14:23
  • If the file is/was already tracked, listing it in `.gitignore` has no effect. A file is tracked if and only if it is in the *index*. The index changes whenever you (a) check out a commit; (b) `git add` a file to copy it over the existing index entry; (c) `git add` a file that was not *in* the index so that it now is; and/or (d) `git rm` a file from the index. After such a change, if the file *is* in the index, it *is* tracked. If not, it is *not* tracked. Only when it is untracked does `.gitignore` affect it. – torek May 26 '17 at 14:50

1 Answers1

0

The file is already part of either HEAD (which means you were already tracking it... in which case .gitignore is not considered) or the file was not being tracked but you added it into the index before you added it into the .gitignore file. If it's the second case, you should try resetting it (which removes it from the index) and it won't bother you again. If it's the first case, then you could either remove it from index (keeping it on the FS) with git rm --cache in which case it will disappear on the next revision or you could remove from the history of the branch altogether which normally means rewriting history of the branch (and which has consequences): Completely remove file from all Git repository commit history

eftshift0
  • 26,375
  • 3
  • 36
  • 60