跳转至

Git Submodule: Data & Code Repository Separate

Just follow my mind

  1. parent repository ignore the sub directory in .gitignore
  2. Normal git usage in child repository, eg. init commit push
  3. submodule for what?
    1. for auto upload and init multi-subgit to target git commit

submodule

submodule is hard to use when it will be blocked under big sub-srepository.

I recommend to use .gitignore or just use ln -s xxx yyy

chatgpt balabala

Adding a Git repository inside another Git repository, often referred to as a "submodule," is a way to manage a separate repository as a part of your main project. This is particularly useful when you want to include another project within your project and keep them separate.

Here's how you can add a submodule and set up .gitignore for the outer repository:

  1. Add a Submodule:

    Navigate to the root of your outer Git repository and run the following command:

    git submodule add <repository_url> <submodule_path>
    

    Replace <repository_url> with the URL of the repository you want to add as a submodule, and <submodule_path> with the relative path within your outer repository where you want to place the submodule.

  2. Update and Initialize Submodule:

    After adding the submodule, you need to update and initialize it:

    git submodule update --init --recursive
    

    This command fetches the submodule's content and initializes it.

  3. Set Up .gitignore:

    To ignore the submodule's content and avoid committing it to the outer repository, you need to add the submodule path to the .gitignore file of the outer repository. For example, if your submodule is located in a directory called "submodule_folder," add the following line to the .gitignore file:

    submodule_folder/
    
  4. Working with Submodules:

    When you clone the outer repository on another system or share it with others, they will need to run git submodule update --init --recursive to fetch and initialize the submodule's content.

    To make changes to the submodule, navigate into the submodule directory and work as you would in a regular Git repository. When you commit changes in the submodule, you will need to push them to its remote repository. After that, commit the updated submodule reference in the outer repository.

    To update the submodule to the latest version available, you can navigate into the submodule directory and run git pull origin master (or the appropriate branch) to update its content. Then, commit the updated reference in the outer repository.

Remember that submodules have their own independent version control, so you need to manage them separately. Submodules provide a way to incorporate external projects into your main project while keeping their development and versioning separate.

需要进一步的研究学习

暂无

遇到的问题

暂无

开题缘由、总结、反思、吐槽~~

参考文献

上面回答部分来自ChatGPT-3.5,没有进行正确性的交叉校验。