Arshad Mehmood

Search the blog

    Today I Learned

    Fixing Detached HEAD in a Git Submodule

    git

    When working with Git submodules, you might encounter a situation where the submodule is in a detached HEAD state. This can be problematic if you need to make changes and commit them. Here’s how you can fix it:

    Steps to Fix Detached HEAD

    1. Navigate to the Submodule Directory

      cd path/to/your/submodule
    2. Check the Current Status

      # if the master branch already exists locally:
      git branch -u <origin>/<branch> <branch>
      # else:
      git checkout -b <branch> --track <origin>/<branch>

    source

    I am a helpful link