-2

In a Git repo I have a folder with a database settings file. The content in it depends on the local DB setup (host, database name, username, pass, etc.)

If I change the file content to fit my local setup, my collaborator should not receive these changes. Same if they change their copy of the file.

How is this done?

Letting the file be uploaded/included first, and then add an ignore to that folder/file afterwards?

random
  • 9,774
  • 10
  • 66
  • 83
mowgli
  • 2,796
  • 3
  • 31
  • 68
  • possible duplicate of [Git: Ignore tracked files](http://stackoverflow.com/questions/10755655/git-ignore-tracked-files) – Sascha Wolf Aug 04 '14 at 07:25

2 Answers2

1

Add an example settings file to the repository with a different name (e.g. database.settings.example) with just placeholders like PASSWORD instead of real data. This should make it easy to recreate your local settings if they get lost.

Don't add the real settings file to the repository. Use a .gitignore to specifically exclude the real settings file. That way, all developers can create their own version and not have to worry about accidentally checking it in.

Matthew Strawbridge
  • 19,940
  • 10
  • 72
  • 93
0

You can achieve this by asking git to temporarily not save any changes to those files.

You can do that by first pushing a version of the file and then doing git update-index --assume-unchanged <file>. This will ask git to temporarily disallow tracking that file. Any changes you make to that file will be ignored by git. When you want to track the changes to the file again, you can do git update-index --no-assume-unchanged <file> which will start tracking the changes back again.

gravetii
  • 9,273
  • 9
  • 56
  • 75
  • Ok. Using terminal (I'm on mac), navigating to that folder and then typing that command? – mowgli Aug 03 '14 at 18:14
  • And does my collaborator have to do the same? – mowgli Aug 03 '14 at 18:20
  • You can go to one folder above the folder in question and run the command with a `/` after the folder name so that it is used for all the files in the folder. Yes, your collaborator also needs to the same if he's pushing to the repo. – gravetii Aug 03 '14 at 18:26