Fijoy Vadakkumpadan
Fijoy Vadakkumpadan

Reputation: 668

Branching in a git repo with submodules

Say I create a git repo with a submodule in it. Then I clone the repo (with the submodule) and create a branch in my local repo. Will that branch include the submodule? If I change 2 files in the repo, f1 an f2, with f1 in the submodule and f2 outside of the submodule, and then commit my change, will that commit include both files? If I then push the commit, will that change the remote submodule?

Upvotes: 0

Views: 613

Answers (2)

letthefireflieslive
letthefireflieslive

Reputation: 12674

Yes it will include the submodule but it will not commit f1 to the submodule's repo.

Think of submodule as a subrepo. It is a separate repository REFERENCED in your current repo. Imagine that many team/repo is referencing/using that repository via submodule too.

Upvotes: 0

kosist
kosist

Reputation: 3057

  1. Your new branch will include submodule.
  2. Submodule - is a separate repository. So in order to save changes, you need to commit first of all to submodule repository. Then, you could commit to your main repository that submodule has been changed. Overall, "main" repository points to some specific commit of submodule repository.
cd SubmoduleRepo
git commit --all -m "Change submodule code" // commit changes directly to submodule repo
git push submodule_origin // push changes to remote submodule repo
cd .. // go back to main repository working folder

git add SubmoduleRepo // commit that submodule repo was changed
git commit -m "Updated submodule" 
git push origin // push changes for the main repo

Upvotes: 1

Related Questions