I have a JavaScript project where I have .config file. I want to be able to make changes to this file without them being tracked by git, so that the changes I make stay local and don't get push to the remote repository when I push. But I also want the file itself to be pushed but without the new content. Currently the file is already available in .gitignore but whenever I make changes to it, they still show when I do git status. How can I make git forget about any changes to this file yet push it to the remote repository?
Asked
Active
Viewed 696 times
1
-
No I tried it. After I do that, and then change the content and try to switch to another branch I can't although the file doesn't show up anymore on git status – somnso Oct 07 '21 at 08:12
-
1The common way to handle such a case is to create an example file *.config.example* that is committed to the repo. When you clone the repository, you can copy the example file to *.config*, which will be in the .gitignore. Also you can use environment variables so no changes are made to the file – thchp Oct 07 '21 at 08:23
-
Not really. I have been digging the internet for days and I already tried that and the result was like the comment i wrote above – somnso Oct 07 '21 at 08:23
-
@thcp if I copy .config.example into .config wouldn't i end up in the same situation? – somnso Oct 07 '21 at 08:27
-
If you never add `.config` to any commit, by keeping it git-ignored, the copy from the example to the config doesn't affect Git at all, and updates to the example don't affect the `.config` file that's never in Git. Note that this is both good (nobody has their config clobbered) and bad (nobody updates their config when the example updates). – torek Oct 07 '21 at 09:40
-
https://stackoverflow.com/a/3318202/7976758, https://stackoverflow.com/a/69476874/7976758 – phd Oct 07 '21 at 11:45