Luka Špoljarić
Luka Špoljarić

Reputation: 1009

Git ignore file after initial push (read only)

I want to commit an initial version of the file to Git and then disallow modifications of that file. How can that be done? I have tried: - adding the file to .gitignore after the initial push (but that wont work because the file is already tracked). - git rm -rf --cached , but that deletes the file from the repository on next commit.

Upvotes: 3

Views: 919

Answers (2)

ramwin
ramwin

Reputation: 6286

I met the same problem in programing. My project have a file named setting.cfg. But my collegues should change it a little for his own environment. We want to share the setting.cfg file and change it without pushing to the remote repository.

Finally, we created a file named setting.cfg_bak, and ignore the setting.cfg:

git rm setting.cfg
echo "setting.cfg" >> .gitignore`

If you want to use the file, you should copy setting.cfg_bak to setting.cfg, and modify setting.cfg for you own needs. After this, the modification will not be pushed to the remote repository.

Upvotes: 1

Danilo Souza Morães
Danilo Souza Morães

Reputation: 1593

If you are considering using .gitignore for that I'm assuming you're ok with configuring every local repository for this. If so, you could use git update-index --skip-worktree path/to/file. This will prevent changes to the file from being commited and/or tracked.

Upvotes: 1

Related Questions