How can I prevent composer from detaching a module's head? How can I prevent composer from leaving a module's git status as a "detached head" when updating 

Whenever I use composer to install or update one of my modules or themes, it downloads and overwrites the module's files into the expected directory but leaves the git status in a 'detached head' state and so subsequent development work is not staged to the expected commit until I reset the head ... which only takes a moment but ... I would prefer not to have to remember to do this each time.

Could it be the way I tag the commit of latest dev work? I git push the commit; git tag it; and git push --tags in the belief that git will not push tags and the commit simultaneously.

As an example:

A theme's complete composer.json on GitHub.

{
  "name": "iainhouston/pellucid_monoset",
  "description": "Drupal 8 Theme for pellucid_build",
  "type": "drupal-theme",
  "license": "GPL-2.0+",
  "keywords": ["pellucid", "php"],
  "homepage": "https://iainhouston.com",
  "minimum-stability": "dev",
  "authors": [
    {
      "name": "Iain Houston",
      "email": "iainhouston@mac.com"
    }
  ],
  "require": { }
}


The theme's entries extracted from the project's composer.json

"repositories": [{
    "type": "composer",
    "url": "https://packages.drupal.org/8"
    },
    ...
    {
    "type": "git",
    "url": "https://github.com/iainhouston/pellucid_monoset.git"
    },
    ...
mradcliffe is correct:


  composer checks out the git commit hash rather than a branch if I recall correctly.


This is fairly easy to deal with though. For example, if your main branch is 8.x-1.x, then you do some work on detached head, you can commit the work on the detached head, which will give you a hash. You then check out the 8.x-1.x branch, and merge the hash. Since the detached head has the 8.x-1.x branch upstream, it can be merged back into that branch after you make your changes.

Example:

$ git status
HEAD detached at aa284c1
$ git add file.php
$ git commit -m "Committed file.php"
[detached HEAD ef37212] Comitted file.php
$ git checkout 8.x-1.x
$ git merge ef37212


If you realize early enough, you can actually just run git add on all your changed filed, then check out  the 8.x-1.x branch. Then you can continue to work there, or make a commit on that branch. Or you can even create a new branch from 8.x-1.x and continue your work in that branch.