Reputation: 71
Is there a way in Git to define special rights to a certain file or folder?
I have a Node project that is built using a Docker-Compose YML file. My intention is that the team working on this project can modify any code, except the Docker-Compose YML file. I would like to prohibit pushes of that file to anyone except me. Is there a way to achieve this in Git?
Upvotes: 1
Views: 1593
Reputation: 77014
There is no intrinsic way to do this with Git, but there are tools that can help.
pre-receive
hook (possibly with push certificates or commit signing) and reject pushes from anyone other than you.Upvotes: 2
Reputation: 9008
You can set the skip-worktree
flag for restricted files like this:
git update-index --skip-worktree path/to/the/file
That gives a little different effect from what you need, but provided proper convention within the team, it should pay off: skip-worktree
makes git ignore any local changes made to a specified tree (files), so no matter if your teammates change it or not, git does not track these changes. However git still tracks remote changes, so git pull
command will update content of the files.
The main disadvantage is that this flag should be set locally on all machines you need those file local changes to be ignored on. For the machines you going to have possibility to push those files, just do not set this flag, or unset it with the following command:
git update-index --no-skip-worktree path/to/the/file
Upvotes: 0
Reputation: 42551
Yes, you can use .gitignore
file - this file will contain the files (paths) that should be ignored by git during commits
This file should be a part of your project (you should commit and push it) so that everyone in your project will get it.
To "suppress" gitignore you can git add --force docker-compose.yml
- so that only you'll use this command.
Upvotes: 0