git submodules , gitslave, git subtree or a simpler solution
<p>We have a git repository with N folders.</p>

<pre><code>Repo
|-Folder1
|-Folder2
|- ...
|-FolderN
</code></pre>

<p>With different collaborators we would like to share different folders. Each collaborator should have access only to his allowed subset of folders. What is the "good" way to achieve this using git?</p>

<hr>

<p>An answer was to use <code>git submodules</code>. But after I read this article: 
<a href="https://codingkilledthecat.wordpress.com/2012/04/28/why-your-company-shouldnt-use-git-submodules/" rel="noreferrer">https://codingkilledthecat.wordpress.com/2012/04/28/why-your-company-shouldnt-use-git-submodules/</a>
I understood that you need to have a good mastery of git (which is not the case of our collaborators) in order to not have problems when using <code>git submodules</code>.</p>

<p>I read about some possible alternatives like <code>gitslave</code>, and <code>git subtree</code>. <code>gitslave</code> seemed to be a good solution but still a complex solution in my opinion.</p>

<p>Here is my simple solution and I would like to know if it can have some very bad drawbacks : </p>

<p>-Having a simple repository for each Folder and a repository for Repo. Then add all the files in Folder1, ..., FolderN in the main Repo. </p>

<p>-globalpush script:</p>

<pre><code>function globalpush(){
REPOS="$HOME/Repo/
       $HOME/Repo/Folder1
       $HOME/Repo/Folder2
       $HOME/Repo/Folder3
       # ...
       $HOME/Repo/FolderN"   

#do not show untracked files
git config status.showuntrackedfiles no

read -p "Commit description: " description

for repo in ${REPOS}
do
    # if the repo folder exists
    if [ -d $repo ]
    then
        # Go inside the repo
        cd $repo
        echo "-----PUSHING REPO : "$repo"-----"

        #add all modified all deleted TRACKED files
        git add -u .

        git commit --allow-empty -m "$description"
        git push                
    else
        echo "-----COULD NOT FIND : "$repo"-----"
    fi
done

#show untracked files again
git config status.showuntrackedfiles normal
}
</code></pre>

<p>-globalpull script:            </p>

<pre><code>function globalpull(){
REPOS="$HOME/Repo/
       $HOME/Repo/Folder1
       $HOME/Repo/Folder2
       $HOME/Repo/Folder3
       # ...
       $HOME/Repo/FolderN"           

for repo in ${REPOS}
do
    # if the repo folder exists
    if [ -d $repo ]
    then
        # Go inside the repo
        cd $repo
        # pull the modifs.
        echo "-----PULLING REPO : "$repo"-----"
        git pull                        
    else
        echo "-----COULD NOT FIND : "$repo"-----"
    fi
done
}
</code></pre>

<p>The advantages of this solution are:</p>

<p>1 - Simple solution that everyone can understand.</p>

<p>2 - Possibility to give the access rights for each Folder independently.</p>

<p>3 - For the main developers (who have access to Repo) the repository Repo is self-contained, and contains all the history (in case something goes wrong with the repositories of Folder1, ..., FolderN).</p>

<p>4 - when a main developer makes a commit with a given description, a commit with the same description will be created for all the Folders repositories, even those without a modification (--allow-empty), which of course isn't perfect but helps tracking versions that are submitted by main developers.</p>

<p>EDIT : </p>

<p>There seems to be a new command I was not aware of <code>git subrepo</code> ...</p>