Submodules Git manual - JU-DEV-Bootcamps/ERAS GitHub Wiki
Branching strategy = Feature Branching with submodules
The Feature Branching Strategy allows developers to work on new features or bug fixes in isolated branches within submodules. This approach helps maintain a stable main branch while enabling parallel development. Steps to Implement Feature Branching in Submodules
Manual for Using Feature Branching Strategy in Submodules
1. Clone the Main Repository
If you haven't already cloned the main repository that contains the submodule, do so with the following command:
git clone --recurse-submodules <main-repo-url>
This command clones the main repository and initializes its submodules.
2. Navigate to the Submodule Directory
Change to the directory of the submodule where you want to create a feature branch:
cd path/to/submodule
3. Fetch Latest Changes
Before creating a new feature branch, ensure you have the latest changes from the remote repository:
git fetch origin
4. Create a New Feature Branch
Create and switch to a new branch for your feature. Use a descriptive name that reflects the feature or bug fix:
git checkout -b feature/your-feature-name
5. Develop Your Feature
Make your changes in the submodule. After making changes, you can check the status of your working directory:
git status
6. Stage Your Changes
Once you are satisfied with your changes, stage them for commit:
git add .
You can also specify individual files instead of using . to add all changes.
7. Commit Your Changes
Commit your changes with a meaningful commit message:
git commit -m "Add feature: description of your feature"
8. Push Your Feature Branch to Remote
Push your newly created feature branch to the remote repository:
git push origin feature/your-feature-name
9. Create a Pull Request (PR)
After pushing your branch, go to your remote repository (e.g., GitHub, GitLab) and create a pull request to merge your feature branch into the main branch (usually main or develop). Provide a clear description of what your feature does and any relevant context.
10. Review and Merge
Once the pull request is reviewed and approved by your team members, merge it into the main branch. You can do this through the web interface of your Git hosting service.
11. Clean Up After Merging
After merging, switch back to the main branch in both the main repository and the submodule, and delete your feature branch if it's no longer needed:
a. In submodule directory
git checkout main
git pull origin main # Update local main branch
b. Delete local feature branch
git branch -d feature/your-feature-name
c. Optionally delete remote feature branch if needed
git push origin --delete feature/your-feature-name
Best Practices
- Regularly Sync with Main Branch: Regularly pull changes from the main branch into your feature branch to minimize merge conflicts.
- Descriptive Branch Names: Use clear and descriptive names for branches to make it easier for team members to understand their purpose.
- Frequent Commits: Commit frequently with meaningful messages to document progress and make it easier to track changes.
- Code Review: Encourage code reviews before merging features into the main branch for improved code quality.
Update a submodule to the latest commit
Enter the submodule directory:
cd projB/projA
```bash
Pull the repo from you project A (will not update the git status of your parent, project B):
```bash
git pull origin master
Go back to the root directory & check update:
cd ..
git status
If the submodule updated before, it will show something like below:
# Not currently on any branch.
# Changed but not updated:
# (use "git add ..." to update what will be committed)
# (use "git checkout -- ..." to discard changes in working directory)
#
# modified: projB/projA (new commits)
#
Then, commit the update:
git add projB/projA
git commit -m "projA submodule updated"
(PUSH) Update a submodule to the latest commit -Simplified version
Since git 1.8, we can use:
git submodule update --remote --merge
(PULL) Update local for latest tips (PULL) a submodule to the latest commit -Simplified version
Since git 1.8, we can use:
git submodule update --recursive --remote