Advanced

Using Git Submodules

Setting up a Git Submodule

This guide will take you through the process of creating a Git submodule for your lang files. This will allow developers to grant access to these files without giving access to the rest of the source code. Following this process will preserve the full history for files in your language files directory.

Prerequisites

  • Python 3 and Pip should also be installed for using git-filter-repo.

Procedure

  1. Install git-filter-repo This will allow you to filter out specific directories in your repo. Make sure it’s in your PATH:

    python3 -m pip install --user git-filter-repo

  2. Clone the Repository Clone your repository to a new directory:

    git clone https://github.com/{your-github-username}/{your-repo-name}.git new-lang

  3. Filter the Repository Down to the Lang Directory Navigate into the new directory and filter the repository down to the lang directory. I'll assume your lang files are in a directory called lang:

    cd {new-directory-name}
    git filter-repo --path lang/
    
  4. Create a New Empty Repo on Github Then, push the new repository (containing just the lang files) to GitHub:

    git remote add origin https://github.com/{your-github-username}/{new-lang-repo-name}.git
    git push -u origin main
    
  5. Move the Lang Files Up a Level Move the lang files up a level in the directory structure and commit the changes:

    mv lang/* .
    git add .
    git commit -m "move files up a level"
    git push
    
  6. Remove the Lang Directory From the Original Repository Navigate back to the original repository and remove the lang directory:

    cd {original-repo-directory}
    git rm -r lang
    git commit -m "Untracking lang directory"
    git push
    
  7. Add the New Repository as a Submodule Add the new repository (containing just the lang files) as a submodule to the original repository:

    git submodule add https://github.com/{your-github-username}/{new-lang-repo-name}.git
    git commit -m "added lang as a submodule"
    git push
    

And there you have it! You now have a submodule for your lang files. You can now add collaborators to the lang repository without giving them access to the rest of your source code.

Previous
The Basics