Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing git module branch

I'm using git submodule in order to track a subproject. The submodule points at a specific branch, but I now need to change it.

I've tried to manually edit the .gitmodules file and change the branch = entry, but every command to update the repo I give later doesn't do anything or fails.

I've tried

git submodule sync # Succeeds, but nothing happens
git submodule update # Doesn't do anything
git submodule update --remote # fails with Needed a single revision

The subproject did correctly check out and gitk in there shows that it does indeed have the new branch that I need to switch to. I could do this manually and commit the new hash but I'm not sure whether git submodule would truly understand the change this way.

I've also tried deleting all submodule folders (including inside the .git folder) and re-running

git submodule update --init --recursive --remote

But I still get the project to the same state as before (I assume because it's still updating to the committed hash).

like image 202
Svalorzen Avatar asked Jan 25 '18 18:01

Svalorzen


1 Answers

Clone again, and then:

  • change branch inside your submodule

     cd submodule
     git checkout -b anotherBranch
     # if it is a new branch, push it first.
     git push -u origin anotherBranch
    

Then reflect that change in the parent repo:

    cd ..
    git config -f .gitmodules submodule.<pathToSubmdule>.branch anotherbranch
    git add .
    git commit -m "record new gilink, and modified .gitmodules"
    git push

Try then to clone again your parent repo to check everything is as expected.

like image 150
VonC Avatar answered Sep 20 '22 08:09

VonC