Last active
November 22, 2023 02:22
-
-
Save juanonsoftware/4453ec06799cdf8ae93a999d2804d9ea to your computer and use it in GitHub Desktop.
Git Submodule practices
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
To add other repos as submodules in an existing git repo | |
1. Create a public repo for submodule https://github.com/juanonsoftware/PocGitAsPublicSubmodule, with some content. | |
2. Checkout the main public repo https://github.com/juanonsoftware/PocGitWorkflows | |
3. Run a command to add the child-repo as a submodule | |
git submodule add -f https://github.com/juanonsoftware/PocGitAsPublicSubmodule.git PublicSubmodule | |
4. If any error, delete the folder in parent repo and in .git/module | |
When success, it will say: | |
Cloning into 'D:/Dev/PocGitWorkflows/PublicSubmodule'... | |
remote: Enumerating objects: 3, done. | |
remote: Counting objects: 100% (3/3), done. | |
remote: Total 3 (delta 0), reused 3 (delta 0), pack-reused 0 | |
Receiving objects: 100% (3/3), done. | |
warning: in the working copy of '.gitmodules', LF will be replaced by CRLF the next time Git touches it | |
5. Git commit and git push to update public repo | |
6. Now work on submodule's repo, push new content | |
7. Back to main repo, pull / or view on Git, nothing updated. Because the submodule is reference to a specific commit | |
8. Now to update the submodule, we run below command: | |
git submodule update --remote | |
Output will look like this: | |
remote: Enumerating objects: 4, done. | |
remote: Counting objects: 100% (4/4), done. | |
remote: Compressing objects: 100% (2/2), done. | |
remote: Total 3 (delta 0), reused 3 (delta 0), pack-reused 0 | |
Unpacking objects: 100% (3/3), 272 bytes | 20.00 KiB/s, done. | |
From https://github.com/juanonsoftware/PocGitAsPublicSubmodule | |
41bb389..a6e3ee1 master -> origin/master | |
Submodule path 'PublicSubmodule': checked out 'a6e3ee179e377f04303d8d5f6019bb1991116e8e' | |
9. Add the change, commit, push to public repo for other to get it | |
10. We can view on Github also |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To create private submodule
Create a private repo https://github.com/juanonsoftware/PocGitAsPrivateSubmodule
Commit some data to private repo
Repeat the steps to init private submodule
git submodule add -f https://github.com/juanonsoftware/PocGitAsPrivateSubmodule.git PrivateSubmodule
Commit and push
So now on Github, other users cannot see the private submodule