1

I am trying to automate a recurring workplace scenario.

I have a repo myRepo which contains a submodule mySub. I create a new branch for myRepo called myRepoBranch and also a new branch for mySub called mySubBranch. I commit changes in both branches and submit them for a pull request.

Issues arise where code in myRepoBranch directly depends on code in mySubBranch. If after submitting my pull request I checkout master and run git pull and git submodule update, mySub will no longer point to mySubBranch. This behaviour is expected and is perfectly fine for master. But if I need to checkout myRepoBranch again, I will also have to manually checkout mySubBranch for the submodule.

Is there a way to automate this manual submodule checkout? Is it possible to bind a specific submodule branch to a specific main repo branch?

1

1 Answer 1

0

In git 1.8.2+ git submodule add -b branch_name URL_to_Git_repo optional_directory_rename

git 2.10+ added a great feature.

The name of the branch is recorded as submodule..branch in .gitmodules for update --remote. A special value of . is used to indicate that the name of the branch in the submodule should be the same name as the current branch in the current repository.

git submodule add -b . URL_to_Git_repo optional_directory_rename # update your submodule git submodule update --remote 

How can I specify a branch/tag when adding a Git submodule?

Sign up to request clarification or add additional context in comments.

1 Comment

Watch out for HTML characters, the text got rendered as submodule..branch rather than submodule.<branch>.branch as StackOverflow markdown thinks <branch> is a bogus HTML directive and strips it from the generated result...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.