diff --git a/sette/all_functions.sh b/sette/all_functions.sh
index e8bc906cdcb328724bf82b9cad6a246d57fe495f..326b38d1fb7069d5e6d4062dc87625b878d83a3e 100755
--- a/sette/all_functions.sh
+++ b/sette/all_functions.sh
@@ -171,7 +171,11 @@ clean_config() {
 
 # define validation dir
 set_valid_dir () {
-    REVISION_NB=`git -C ${MAIN_DIR} rev-list --abbrev-commit origin | head -1l`
+    if [ ${DETACHED_HEAD} == "no" ] ; then
+      REVISION_NB=`git -C ${MAIN_DIR} rev-list --abbrev-commit origin | head -1l`
+    else
+      REVISION_NB=${DETACHED_CMIT}
+    fi
     REV_DATE0="`git -C ${MAIN_DIR} log -1 | grep Date | sed -e 's/.*Date: *//' -e's/ +.*$//'`"
     REV_DATE=`${DATE_CONV}"${REV_DATE0}" +"%y%j"`
     REVISION_NB=${REV_DATE}_${REVISION_NB}
diff --git a/sette/sette.sh b/sette/sette.sh
index 8724abd3184d66ccb858476b6d8c3c481eb90bcd..69aee9704262b55e798713cf3b3bfa0ebcccab96 100755
--- a/sette/sette.sh
+++ b/sette/sette.sh
@@ -36,10 +36,25 @@ export USER_INPUT='yes'        # Default: yes => request user input on decisions
                                #                 3. regarding creation of directories
 #
 # Check that git branch is usable
+export DETACHED_HEAD="no"
 git branch --show-current >& /dev/null
 if [[ $? == 0 ]] ; then
   # subdirectory below NEMO_VALIDATION_DIR defaults to branchname
   export SETTE_SUB_VAL="$(git branch --show-current)"
+  if [ -z $SETTE_SUB_VAL ] ; then
+   # Probabably on a detached HEAD (possibly testing an old commit).
+   # Verify this and try to recover original commit
+   MORE_INFO="$(git branch -a | head -1l | sed -e's/.*(//' -e 's/)//' )"
+   if [[ "${MORE_INFO}" == *"detached"* ]] ; then
+     export DETACHED_HEAD="yes"
+     export DETACHED_CMIT=$( echo \\${MORE_INFO} | awk '{print $NF}' )
+     # There is no robust way to recover a branch name in a detached state
+     # so just use the commit with a prefix
+     export SETTE_SUB_VAL="detached_"${DETACHED_CMIT}
+   else
+     export SETTE_SUB_VAL="Unknown"
+   fi
+  fi
   export SETTE_THIS_BRANCH=${SETTE_SUB_VAL}
 else
   # subdirectory below NEMO_VALIDATION_DIR defaults to "MAIN"
diff --git a/sette/sette_eval.sh b/sette/sette_eval.sh
index 93d70715a693565cdc967d4a057c7f6bb7b7e81f..cfe9fe00770d39232e13cf8cfcff6e0bc3976f7b 100755
--- a/sette/sette_eval.sh
+++ b/sette/sette_eval.sh
@@ -255,11 +255,31 @@ function runcmpres(){
 #
 if [ ${quiet} -eq 0 ] ; then echo "" ; fi
 localchanges=`git status --short -uno | wc -l`
-revision=`git rev-list --abbrev-commit origin | head -1l`
+# Check that git branch is usable and use it to detect detached HEADs
+git branch --show-current >& /dev/null
+if [[ $? == 0 ]] ; then
+  branchname="$(git branch --show-current)"
+  if [ -z $branchname ] ; then
+   # Probabably on a detached HEAD (possibly testing an old commit).
+   # Verify this and try to recover original commit
+   MORE_INFO="$(git branch -a | head -1l | sed -e's/.*(//' -e 's/)//' )"
+   if [[ "${MORE_INFO}" == *"detached"* ]] ; then
+     revision=$( echo \\${MORE_INFO} | awk '{print $NF}' )
+     # There is no robust way to recover a branch name in a detached state
+     # so just use the commit with a prefix
+     branchname="detached_"${revision}
+   else
+     branchname="Unknown"
+   fi
+  else
+   revision=`git rev-list --abbrev-commit origin | head -1l`
+  fi
+else
+  branchname="Unknown"
+fi
 rev_date0=`git log -1 | grep Date | sed -e 's/.*Date: *//' -e's/ +.*$//'`
 rev_date=`${DATE_CONV}"${rev_date0}" +"%y%j"`
 revision=${rev_date}_${revision}
-branchname=`git branch --show-current`
 if [[ $localchanges > 0 ]] ; then
  if [ ${quiet} -eq 0 ] ; then  echo "Current code is : $branchname @ $revision  ( with local changes )" ; fi
  lastchange=${revision}+
diff --git a/sette/sette_rpt.sh b/sette/sette_rpt.sh
index 16998096f82cb555f23696ec72672277500a8656..dfc9db7a3c350b7896c9704a232c219e28243e5f 100755
--- a/sette/sette_rpt.sh
+++ b/sette/sette_rpt.sh
@@ -567,11 +567,31 @@ function identictest(){
 #
 echo ""
 localchanges=`git status --short -uno | wc -l`
-revision=`git rev-list --abbrev-commit origin | head -1l`
+# Check that git branch is usable and use it to detect detached HEADs
+git branch --show-current >& /dev/null
+if [[ $? == 0 ]] ; then
+  branchname="$(git branch --show-current)"
+  if [ -z $branchname ] ; then
+   # Probabably on a detached HEAD (possibly testing an old commit).
+   # Verify this and try to recover original commit
+   MORE_INFO="$(git branch -a | head -1l | sed -e's/.*(//' -e 's/)//' )"
+   if [[ "${MORE_INFO}" == *"detached"* ]] ; then
+     revision=$( echo \\${MORE_INFO} | awk '{print $NF}' )
+     # There is no robust way to recover a branch name in a detached state
+     # so just use the commit with a prefix
+     branchname="detached_"${revision}
+   else
+     branchname="Unknown"
+   fi
+  else
+   revision=`git rev-list --abbrev-commit origin | head -1l`
+  fi
+else
+  branchname="Unknown"
+fi
 rev_date0=`git log -1 | grep Date | sed -e 's/.*Date: *//' -e's/ +.*$//'`
 rev_date=`${DATE_CONV}"${rev_date0}" +"%y%j"`
 revision=${rev_date}_${revision}
-branchname=`git branch --show-current`
 if [[ $localchanges > 0 ]] ; then
  echo "Current code is : $branchname @ $revision  ( with local changes )"
  lastchange=${revision}+