Reputation: 5607
I have a file in a remote repository (BitBucket) that I don't want Git tracked, but I do want it to be part of the repository. When pulling that repo to a local computer this file needs to be pulled too. However, I don't then want local users to push changes (i.e. I don't want Git to track it).
I add that file to .gitignore
. However, it just won't ignore it. I think it might be something to do with the fact that it is part of the repository as any other file would be ignored (e.g. if I create a random file and add it to .gitignore it IS ignored).
I have tried everything on this page: http://365git.tumblr.com/post/519016351/three-ways-of-excluding-files but it just won't stop tracking it.
This is the only thing that works but isn't very user friendly and I've heard that the changes might actually be committed, just not visible in the staging area (when doing a git status):
git update-index --assume-unchanged [file]
Regardless, I just need a way of having a file in a remote repository (GitHub/BitBucket) that can be pulled but not edited, updated or monitored by Git. Is it possible?
Upvotes: 1
Views: 242
Reputation: 387795
Git will never ignore files that were added explicitely, and Git’s ignore list only applies to untracked files.
So as soon as you add the file to the repository, the .gitignore
contents are ignored for that file. There is no way around this, and it makes a lot of sense that it works this way. It’s simply not possible to make Git ignore a file but track it at the same time. The only way to tell Git to ignore changes to it afterwards is to use update-index --assume-unchanged
.
The usual way to handle this use case, that is having some kind of default configuration inside the repository but allow users to customize it without having those customizations in the repository again, is to use one of two ways to handle it: One is to specify an example configuration file. So instead of adding e.g. config.ini
to the repository, you add config.example.ini
to it and ask users to copy it manually to config.ini
before making their custom changes. config.ini
itself is ignored so it won’t be added to the repository. The other way is to specify multiple levels of configuration. For example you have a config.ini
—which is in the repository and contains the default configuration—and also load a config.user.ini
with your application which makes it possible to overwrite settings. That config.user.ini
is again ignored and a user can create it manually if they want to change their own configuration.
Upvotes: 2