The basic problem is that checkout
is comparing the desired revision (my_tag
, master
) against what's in HEAD
in the --bare
repo. (And the --bare
argument is doing nothing.) So with my_tag
, it says you're already in detached HEAD
mode and on the desired rev—i.e., it should not change HEAD
—and looks into the target directory, /var/www/test/
, and sees that the files have been removed and gives you the D
status for each. It assumes they were there because of the index (see below).
When you switch to checkout master
, it figures: OK, you're moving from this detached-HEAD
to master
, it updates HEAD
and checks out the changed files. But .gitmodules
is the same in my_tag
and head
, so that one remains D
eleted.
If you use checkout -f
, it will assume it should replace the missing files.
Git also has the bad habit :-) of using $GIT_DIR/index
to record what it is doing with the checkout, as well as $GIT_DIR/HEAD
. This leads to left-behind files when files are removed from the thing you're trying to deploy. If the target directory is emptied out before doing a checkout -f
that should be OK though. (Alternatively, set GIT_INDEX_FILE
in the environment, naming a file you keep along with each unique deployment. I have not experimented with this but it should work well.)