0

There's a file I'd like to maintain on the remote git repo but I'd like to be only one that can make changes/commit to it. Other users may update it locally but when they commit, this particular file will be ignored for them. Ideally, there would be as few steps as possible (None would be awesome) for all other users to follow to achieve this behavior. Any ideas?

I was thinking of maybe adding this file to a global gitignore and possibly making the file an exception on a local gitignore or in the exclude config (not sure if this would even work the way I imagine it would).

Kev
  • 11
  • 1
  • 4

3 Answers3

0

Here's a link that might help your question.

I think I found another Stack Overflow post that might help. The process of creating a user-specific .gitignore file seems to be populating a file called GIT_DIR/info/exclude or entering git config --global core.excludesfile $HOME/.gitignore into Bash, but there's a lot of extra information in the linked post that might help you.

0

One approach is to add the affected file to a checked-in .gitignore file, and then when editing deliberately you would use git add -f to override the .gitignore and overwrite the file. That's something you or anyone else could do, and should avoid stray or unintentional edits.

Note that if local users overwrite the file in the repository with local changes, it may be somewhat annoying for them to merge or overwrite when you check in changes. You can specify how git checkout handles working tree conflicts with -f and -m, but if there are alternative approaches using separate files (e.g. "base.config" vs "user.config") you might consider that instead.

Jeff Bowman
  • 90,959
  • 16
  • 217
  • 251
  • This might be how I need to do this and just make sure other users don't force the add if they don't need to. – Kev Feb 08 '20 at 19:33
  • You can also look into commit hooks to make sure nobody else edits the file, but those can be overridden too. At some point git is not going to be the best choice for protecting against a determined power user _aside from_ protecting against pushing their changes to _a server you control_. That said, you can make it hard to get wrong on accident, which is a reasonable outcome. – Jeff Bowman Feb 08 '20 at 23:52
0

If guys from your team execute:

git update-index --skip-worktree yourFile

or

git update-index --assume-unchanged yourFile

git will treat this file as unchanged even if there are local changes

IKo
  • 4,998
  • 8
  • 34
  • 54