0

I am trying to do the following thing-

  1. I have a folder config which I wanted to include to the git repository first time and I could do that without fail.

  2. Next, I make a change in .gitignore file so that it excludes any changes from that directory by adding

/config/

  1. Next, I commit the change and update the branch

  2. Then I make a change to a file which is under config directory but it shows under changed file when I do git status

Is there a way so that I can include a folder first time and then tell git to ignore from next time onwards.

Any help is highly appreciated.

Prithviraj Mitra
  • 11,002
  • 13
  • 58
  • 99
  • 1. Can you provide more detail about why you need to set up your project this way? Possibly there’s another solution, such as keeping a default/sample config and then having a custom config that never goes to source. 2. Have you considered git update-index —skip-worktree? This would work if you’re the sole collab but may be more complex if you have others to explain this to. – JBallin Jul 15 '20 at 23:10
  • 1
    There are thousands of questions about how to save developer-specific configuration files outside of Git. Have you tried reading [ask] and doing research? – CodeCaster Jul 15 '20 at 23:17
  • That answer is wrong. See the [Git FAQ](https://git-scm.com/docs/gitfaq#Documentation/gitfaq.txt-HowdoIignorechangestoatrackedfile) for the answer to this question. – bk2204 Jul 16 '20 at 01:35
  • .gitignore does not work on tracked files. If you added /committed a file, git does not care that you put it in .gitignore, it will notice if you change it. – eftshift0 Jul 16 '20 at 03:10

1 Answers1

0

Is there a way so that I can include a folder first time and then tell git to ignore from next time onwards.

No: I usually version:

  • config file templates
  • an init script which is executed by the user cloning the repository, and generating (if the actual config files do not yet exist) the config files from the template files.

That way:

  • the config files remain private (not version)
  • they are ignored by the .gitignore
  • they can be modified as many time as you want.
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250