Alan Kis Alan Kis - 1 year ago 182
Git Question

GIT - How to remove local file from tracking, but leave copy on remote repository?

I have a following scenario, in my Rails app, but scenario can be adopted to any other application, where you don't want to push your development credentials to public repository like Github.

So I have file

, where I have my local MySQL database credentials, and I don't really want to push this details to public, so idea is to have one copy, for example initial
with dummy data, then push it to remote repository, add it to .gitignore, and remove it from tracking, and then update this file just in local repo with actual database credentials. After I did this with:

git rm --cached config/database.yml
, file actually was deleted from my remote repository. How can I prevent this, and after I push initial config file, ignore it, but leave initial commit of this file on remote repo?

My .gitignore has this line to ignore file

# Ignore config/database.yml

Long story short, I want to have two different copies of file in my local and remote repository, and I don't want to track changes once I will update
file with actual MySQL server connection credentials.

Answer Source

Never commit database.yml to version control. Add it to .gitignore

Instead commit a copy called example.database.yml with some dummy values. Then your deploy process copies the example and substitutes the secret values.

Otherwise you'll be stuck in a maintenance nightmare of ignoring the config file and then temporarily un-ignoring it when you need to make framework changes, and always lurking the danger of accidentally committing a password to version control.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download