Forum: Ruby on Rails database.yml and .gitignore

0a87fb6bf40485e5a22b9c64a464e83b?d=identicon&s=25 jgoggles (Guest)
on 2008-12-11 18:30
(Received via mailing list)
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!
8217faf2bfdfa7daf10135d41ddd421e?d=identicon&s=25 Jeff Cohen (jeff)
on 2008-12-11 20:32
(Received via mailing list)
On Dec 11, 11:29 am, jgoggles <daniel.wea...@gmail.com> 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
280b78a61a968391b7e07e912be102a8?d=identicon&s=25 Robert Walker (robert4723)
on 2008-12-11 21:09
> 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.
280b78a61a968391b7e07e912be102a8?d=identicon&s=25 Robert Walker (robert4723)
on 2008-12-11 21:14
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

See the README for usage and options.
171ea139761951336b844e708d1547ab?d=identicon&s=25 James Byrne (byrnejb)
on 2008-12-11 22:12
Jeff Cohen 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.
0a87fb6bf40485e5a22b9c64a464e83b?d=identicon&s=25 Dan Weaver (jgoggles)
on 2008-12-19 23:50
(Received via mailing list)
Very helpful.  Thanks guys!

On Dec 11, 2:12 pm, James Byrne <rails-mailing-l...@andreas-s.net>
Fc582698581884352e745d1d4c64699d?d=identicon&s=25 Joshua Muheim (josh)
on 2012-06-07 13:23
> # git status
> # git rm config/database.yml --cache

Notice: it's --cached, not --cache.
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.