Home > Blockchain >  How to prevent other contributers to modify some files in Git?
How to prevent other contributers to modify some files in Git?

Time:02-17

I have some personal directories in git for experimentation code, but it also may be interesting to others to see. For example directories /personA and /personB. How can I achieve the following:

  • each person can modify and commit changes in his personal directory as usual
  • everyone can see all directories
  • however, no one should be able to push changes in the other persons directory (it can be a "soft" solution to prevent when this happens by accident)

The other person's directory could be read-only, or alternatively changes there will always be overwritten by a consequent git pull.

CodePudding user response:

tl;dr: You may be able to achieve your goal, but it will be SCM tool dependent.

As mentioned in the comments, Git by itself does not enforce rules as you have described; it's up to maintainer of the copy of the repo to control those types of rules. Each developer who clones a repo becomes the maintainer of their own copy of a repo, and so you cannot control what they do with their own repo. However, if you control a repo on a server (e.g. GitHub, GitLab, AzureDevops, BitBucket, etc.) you can enforce some type of security depending on what the tools offer. Sometimes you can extend the default security configuration options with server side hooks or additional status checks and custom policies.

Regarding this goal:

...no one should be able to push changes in the other persons directory

Although it may be possible to achieve this with server side settings and custom hooks, note that this type of block is not typical (in my experience). Instead, it's more common to lock down specific shared branches with polices that prevent merging into those branches unless certain conditions are met. When shared branches are locked down in this way, it's common that no one can push to them directly, and a Pull Request is used to merge in changes from another branch. So, the typical scenario would be that anyone could push any kind of change to their own branch, but the policy would enforce that only certain people can modify specific files on the shared branch(es) and so the PR would be blocked if those files are included in the branch to be merged in. Note your goal is still met, but the block happens at "merging into shared branches" rather than at "push".

CodePudding user response:

You can't do this, because if person have access to git repository, person can modify all files in repository

  •  Tags:  
  • git
  • Related