Alan Kis
Alan Kis

Reputation: 1910

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 config/database.yml, 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 database.yml 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 config/database.yml

# Ignore config/database.yml
/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 database.yml file with actual MySQL server connection credentials.

Upvotes: 1

Views: 124

Answers (2)

pathfinderelite
pathfinderelite

Reputation: 3137

You can use

git update-index --assume-unchanged config/database.yml

to ignore local changes to a tracked file.

Upvotes: 0

Jeff Puckett
Jeff Puckett

Reputation: 40971

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.

Upvotes: 1

Related Questions