Search code examples
gitazure-devopsgit-submodules

Get latest commit from a branch other than master branch to submodule


I have 2 ADO repositories - Repo1 & Repo2

Repo1 is set as a submodule in Repo2

[submodule "Repo1"]
    path = Repo1
    url = https://xyz.visualstudio.com/DefaultCollection/abc/_git/Repo1

Let's say I made a change in Repo1 and a new commit is added to 'test' branch (NOT 'master' branch).

I need to get that commit in the submodule in Repo2.

When I tried:

git clone <url-of-Repo2>
cd Repo1
git submodule update --init --recursive

I only see latest commit from 'master' branch not 'test' branch. How can I get latest commit from 'test' branch to submodule?


Solution

  • Do your submodule updates in the repos using the submodules, not in the submodules themselves.

    git -C Repo1 checkout test
    

    and if you want to add/commit it, do that,

    git commit -am "Update Repo1 to its 'test' branch tip"