git clone with different file permissions
-
29-09-2019 - |
Question
On our server are three (in reality: thousands of) text files stored in a bare git repository: A.txt, B.txt, C.txt.
- User "admin" should view/edit them all.
- User "Foo" should view/edit "A.txt" and "B.txt" but he is not allowed to see the content of "C.txt".
- User "guest" should only be allowed to view/edit "A.txt".
All three users should be able to clone the git repository with the files they are allowed to edit.
Is there any possibility to make this with git (...or mercurial)?
Idea: Can I make two clones of the bare git repository with the sparse checkout feature of git for the user "Foo" and "guest" wich include only the files they are allowed to see?
Any other (faster) idea?
Solution
You should:
- have three branches
- guest (with only
A.txt
files) - users (with A and B.txt files)
- admin (with all files)
- guest (with only
That means frequent merges to update the different branches and propagate the different modification.
Plus, with gitolite, you can control who can pull/push what (at a branch level), which means:
- a guest will only be able to pull the
guest
branch. - a foo user will only be able to pull the
guest
branch and theusers
branch, while being able to push theusers
branch (or both branches if you want a user to update the content ofguest
branch). - an admin can pull/pull all branches.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow