# Database.yml and .gitignore

**URL:** <https://www.ruby-forum.com/t/database-yml-and-gitignore/155429>\
**Category:** Rails\
**Created:** [December 11, 2008, 6:30pm UTC](https://www.ruby-forum.com/t/database-yml-and-gitignore/155429 "2008-12-11T18:30:28Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jgoggles](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/838e76/32.png) [@jgoggles](https://www.ruby-forum.com/u/jgoggles)\
**Post date:** [December 11, 2008, 6:30pm UTC](https://www.ruby-forum.com/t/database-yml-and-gitignore/155429/1 "2008-12-11T18:30:28Z")

</div>

Hi,

For some reason git is not ignoring my database.yml file even though I  
have config/database.yml in my .gitignore file. Any suggestions as to  
what the problem might be and/or how I can fix it? It’s causing major  
annoyances. Is there a way to remove the database.yml from the repo  
entirely?

Thanks!

---

<div class="post-metadata">

**Author:** ![jgoggles](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/838e76/32.png) [@jgoggles](https://www.ruby-forum.com/u/jgoggles)\
**Post date:** [December 11, 2008, 8:32pm UTC](https://www.ruby-forum.com/t/database-yml-and-gitignore/155429/2 "2008-12-11T20:32:59Z")

</div>

On Dec 11, 11:29 am, jgoggles [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi,
> 
> For some reason git is not ignoring my database.yml file even though I  
> have config/database.yml in my .gitignore file. Any suggestions as to  
> what the problem might be and/or how I can fix it? It’s causing major  
> annoyances. Is there a way to remove the database.yml from the repo  
> entirely?
> 
> Thanks!

If it got added to your git repo before you specified it in the ignore  
file, I think you have to remove it:

git rm config/database.yml  
git commit -a -m “Removed database.yml”

(maybe save a backup of your database.yml first 🙂

Jeff

---

<div class="post-metadata">

**Author:** ![jgoggles](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/838e76/32.png) [@jgoggles](https://www.ruby-forum.com/u/jgoggles)\
**Post date:** [December 11, 2008, 9:14pm UTC](https://www.ruby-forum.com/t/database-yml-and-gitignore/155429/3 "2008-12-11T21:14:55Z")

</div>

Oh! In fact I don’t actually do any of that manually, but instead I use  
a simple Ruby script that I wrote (before discovering there are probably  
better ways to this, and now Rails Edge has a really cool new template  
system for doing this sort of thing).

If interested you can find the script here…  
[http://github.com/robertwalker/git-a-rails-project/tree](http://github.com/robertwalker/git-a-rails-project/tree)

See the README for usage and options.

---

<div class="post-metadata">

**Author:** ![jgoggles](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/838e76/32.png) [@jgoggles](https://www.ruby-forum.com/u/jgoggles)\
**Post date:** [December 11, 2008, 10:12pm UTC](https://www.ruby-forum.com/t/database-yml-and-gitignore/155429/4 "2008-12-11T22:12:35Z")

</div>

Jeff C. wrote:

> If it got added to your git repo before you specified it in the ignore  
> file, I think you have to remove it:
> 
> git rm config/database.yml  
> git commit -a -m “Removed database.yml”
> 
> (maybe save a backup of your database.yml first 🙂
> 
> Jeff

Safer I think to:

# git status

# git rm config/database.yml --cache

–cache should leave the actual file alone and just remove it from  
tracking\> Backups are always a good thing though.

---

<div class="post-metadata">

**Author:** ![jgoggles](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/838e76/32.png) [@jgoggles](https://www.ruby-forum.com/u/jgoggles)\
**Post date:** [December 19, 2008, 11:50pm UTC](https://www.ruby-forum.com/t/database-yml-and-gitignore/155429/5 "2008-12-19T23:50:57Z")

</div>

Very helpful. Thanks guys!

On Dec 11, 2:12 pm, James B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![jgoggles](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/838e76/32.png) [@jgoggles](https://www.ruby-forum.com/u/jgoggles)\
**Post date:** [June 7, 2012, 1:23pm UTC](https://www.ruby-forum.com/t/database-yml-and-gitignore/155429/6 "2012-06-07T13:23:11Z")

</div>

> # git status
> 
> # git rm config/database.yml --cache

Notice: it’s --cached, not --cache.

---

<div class="post-metadata">

**Author:** ![jgoggles](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/838e76/32.png) [@jgoggles](https://www.ruby-forum.com/u/jgoggles)\
**Post date:** [December 11, 2008, 9:09pm UTC](https://www.ruby-forum.com/t/database-yml-and-gitignore/155429/7 "2008-12-11T21:09:17Z")

</div>

> If it got added to your git repo before you specified it in the ignore  
> file, I think you have to remove it:
> 
> git rm config/database.yml  
> git commit -a -m “Removed database.yml”
> 
> (maybe save a backup of your database.yml first 🙂
> 
> Jeff  
> What I do is rename database.yml to example\_database.yml before the  
> initial commit to git (and have config/database.yml in .gitignore. Then  
> after the initial commit I copy example\_database.yml back to  
> database.yml, which will not be ignored.

Git will only ignore untracked files that are in .gitignore. If you are  
tracking changes to a file the .gitignore has no effect.

The reason I keep example\_database.yml in Git is so that when the  
repository is cloned all I have to do is copy example\_database.yml to  
database.yml and I’m ready to go in the clone.

Note: this way each developer can keep their database password in their  
own untracked copy of database.yml if a password is required. But, they  
won’t have to recreate database.yml from scratch.
