0

I'm collaborating with a colleague through Git. There are some files which he normally shouldn't modify, but it can happen by accident. Moreover, he is not experienced with Git.

What is the best way to make a setting in his Git such that

  • on git push he will never overwrite files on the server in my special directory
  • on git pull (or a similar command) he will always overwrite that directory with the version from the server (even if he changed the files in this directory locally)
Gere
  • 12,075
  • 18
  • 62
  • 94
  • Possible duplicate of [Protecting files in git repository](http://stackoverflow.com/questions/3360092/protecting-files-in-git-repository) – David Z Dec 16 '16 at 13:23

2 Answers2

1

You should create a separate repo for the files that require separate permissions. Then it's easy to deny push access to that repo for people who should not modify those files. You can make one of the repos a submodule of the other, to keep them "in sync."

John Zwinck
  • 239,568
  • 38
  • 324
  • 436
1

Do you have control over the server? A pre-receive hook that checks the pusher and the files pushed and blocks any pushes that violate the policy would do what you want.

If these files are all related, I'm not a fan of making multiple small repos.

As for ensuring that the user's local changes to these files are overwritten on pull... Philosophical differences about allowing somebody you trust so little to touch your code aside... They would need to either do their git pull via a wrapper script that does something like a git checkout -- <restricted paths> afterwards, or alternately have a similar post-pull hook. Both would still require compliance to either run the wrapper or install the hook.

Mort
  • 3,379
  • 1
  • 25
  • 40