Search code examples
gitgitignore

Any way to have a versioned and unversioned .gitignore in the same folder?


I have a situation where I am creating a "starter theme" let's say, and I'm creating the .gitignore file, however this .gitignore is what is controlling what files to add/ignore to the starter theme repo.

Problem is, when the starter theme repo is cloned and pulled down, I want a totally separate .gitignore file, not the same one.

So ideally I would be able to ignore this .gitignore file, and create a separate one that could then be pulled down for use with the starter theme.

Now obviously you won't be able to create two files with the same name, so what if anything is the best way to handle this?

Ideally it would be good for the actual .gitignore file to be the one that is to be used in the starter theme and there was another way I could control what files are ignored so they don't end up in the repo.

I'm aware of git config core.excludesfile; however I have read that this only has local effects and it wouldn't carry over to other users; on top of that, the .gitignore file that is to be used in the actual repo will ignore a lot more, so I don't see how having that file around is going to work.

Perhaps the only way to handle this is to create a secondary ignore file, but name it something like .gitignore-rename-me and then ignoring the actual one itself so it doesn't end up in the starter theme?


Solution

  • That sounds like a job for git branches:

    • the default master branch would have the "different" .gitignore, the one that anyone cloning the repo should use
    • the dev branch would have the .gitignore used for developing the theme.

    You can then merge dev to master, while ignoring a file (.gitignore), in order to add new feature to the theme.