Git Notes - Submodule && detached HEAD

When I forget to add submodule

I moved my media directory to the project as well, since it's a git project I have to add it as a git submodule add, however I forgot to do so and did git add . instead, so on my earlier commit, the folder is shown as a text on Github.


  1. Unstage it

    $ git rm --cached media
  2. Add it in a correct way

    $ git submodule add url_to_repo media

Detached HEAD

My git in media directory somehow got a detached state:

$ git commit -m "aaa"
HEAD detached from 8799335

To fix that2 and merge the untracked changes, so I need to checkout the corresponding branch:

$ git checkout master

Then it shows the log:

Warning: you are leaving 4 commits behind, not connected to
any of your branches:

  69c7986 yEd try
  7f5f6d2 new pics
  eb3656a new pic
  19a5966 2 new pics

If you want to keep them by creating a new branch, this may be a good time
to do so with:

git branch <new-branch-name> 69c7986

Switched to branch 'master'

Then follow the instruction and push:

$ git branch tmp 69c7986
$ git push origin master