diff --git a/scripts/commit_all_submodules b/scripts/commit_all_submodules
index 2ade46f..067c6da 100755
--- a/scripts/commit_all_submodules
+++ b/scripts/commit_all_submodules
@@ -5,28 +5,46 @@ if [[ ! -d .git ]]; then
 	exit 1
 fi
 
+branch=`git symbolic-ref --short -q HEAD`
+if [[ -z "$branch" ]] ||
+   [[ -z "`git rev-parse --symbolic-full-name --remotes=\"*/$branch\"`" ]]; then
+	echo "There is not active upstream branch.  Exiting..."
+	exit 1
+fi
+
 echo "Preparing $PWD for development use"
 if [[ $1 == "" ]]; then
-	read -p "Enter your TDE GIT username []: " -e gituser
+	gituser=`sed -n "/^\[remote \"origin\"\]/,/url/s/\turl = http:\/\/\([^@]*\)@.*/\1/p" <.git/config | grep -v "\(anonymous\|system\)"`
 else
 	gituser=$1
 fi
 
 if [[ $gituser == "" ]]; then
+	read -p "Enter your TDE GIT username []: " -e gituser
+fi
+
+if [[ $gituser == "" ]]; then
 	gituser="anonymous"
 fi
 
 read -p "Enter your commit message []: " -e commitmessage
 
-git submodule foreach "git commit -a -m \"$commitmessage\" || true"
-git submodule foreach "sed -i \"s/system@scm\.trinitydesktop\.org/$gituser@scm\.trinitydesktop\.org/g\" .git/config"
-git submodule foreach "git pull && git push origin master"
+git submodule foreach "[[ -z \"\`git status --porcelain --ignore-submodules\`\" ]] ||\
+    git commit -a -m \"$commitmessage\" || true"
+git submodule foreach "[[ ! -d .git ]] || \
+    sed -i \"s/system@scm\.trinitydesktop\.org/$gituser@scm\.trinitydesktop\.org/g\" .git/config"
+git submodule foreach "git pull &&\
+    [[ \"\`git rev-parse HEAD\`\" == \"\`git rev-parse origin/$branch\`\" ]] ||\
+    git push origin HEAD"
 RETCODE=$?
 if [[ $RETCODE != 0 ]]; then
 	echo "Something went wrong"
 	exit 1
 fi
 
-git commit -a -m "$commitmessage" || true
+[[ -z "`git status --porcelain --ignore-submodules`" ]] ||\
+    git commit -a -m "$commitmessage" || true
 sed -i "s/system@scm\.trinitydesktop\.org/$gituser@scm\.trinitydesktop\.org/g" .git/config
-git pull && git push origin master || true
+git pull &&\
+    [[ "`git rev-parse HEAD`" == "`git rev-parse origin/$branch`" ]] ||\
+    git push origin HEAD || true
diff --git a/scripts/switch_all_submodules_to_head_and_clean b/scripts/switch_all_submodules_to_head_and_clean
index c395e62..443fff8 100755
--- a/scripts/switch_all_submodules_to_head_and_clean
+++ b/scripts/switch_all_submodules_to_head_and_clean
@@ -5,14 +5,25 @@ if [[ ! -d .git ]]; then
 	exit 1
 fi
 
+branch=`git symbolic-ref --short -q HEAD`
+if [[ -z "$branch" ]] ||
+   [[ -z "`git rev-parse --symbolic-full-name --remotes=\"*/$branch\"`" ]]; then
+	echo "There is not active upstream branch.  Exiting..."
+	exit 1
+fi
+
 echo "Preparing $PWD for development use"
 if [[ $1 == "" ]]; then
-	read -p "Enter your TDE GIT username []: " -e gituser
+	gituser=`sed -n "/^\[remote \"origin\"\]/,/url/s/\turl = http:\/\/\([^@]*\)@.*/\1/p" <.git/config | grep -v "\(anonymous\|system\)"`
 else
 	gituser=$1
 fi
 
 if [[ $gituser == "" ]]; then
+	read -p "Enter your TDE GIT username []: " -e gituser
+fi
+
+if [[ $gituser == "" ]]; then
 	gituser="anonymous"
 fi
 
@@ -23,11 +34,15 @@ if [[ ! -e "$THISSCRIPT" ]]; then
 	exit 1
 fi
 
-git reset --hard HEAD
-git clean -dxf
+if [[ ! -z "`git status --porcelain --ignore-submodules`" ]]; then
+	git reset --hard HEAD
+	git clean -dxf
+fi
 git pull
-git reset --hard HEAD
-git clean -dxf
+if [[ ! -z "`git status --porcelain --ignore-submodules`" ]]; then
+	git reset --hard HEAD
+	git clean -dxf
+fi
 
 if [[ -e .gitmodules ]]; then
 	if [[ $gituser == "anonymous" ]]; then
@@ -38,9 +53,10 @@ if [[ -e .gitmodules ]]; then
 
 	git submodule init
 	git submodule update
-	git submodule foreach "git checkout master"
-	git submodule foreach "git pull"
-	git submodule foreach "$THISSCRIPT $gituser"
+	git submodule foreach "[[ -z \"\`git status --porcelain --ignore-submodules\`\" ]] ||\
+	    (git reset --hard HEAD && git clean -dxf)"
+	git submodule foreach "git checkout $branch && git pull"
+	git submodule foreach "[[ ! -d .git ]] || $THISSCRIPT $gituser"
 
 	git checkout -- .gitmodules
 fi
diff --git a/scripts/update_all_submodules b/scripts/update_all_submodules
index d0bf837..54c0889 100755
--- a/scripts/update_all_submodules
+++ b/scripts/update_all_submodules
@@ -6,17 +6,27 @@ if [[ -e /var/lock/update-tde-git-submodules ]]; then
         exit 0
 fi
 
-touch /var/lock/update-tde-git-submodules
-
-PARENTDIR=$PWD
-echo "Working in $PARENTDIR"
 if [[ ! -d .git ]]; then
 	echo "Current directory does not contain a .git folder.  Exiting..."
 	exit 1
 fi
+
+branch=`git symbolic-ref --short -q HEAD`
+if [[ -z "$branch" ]] ||
+   [[ -z "`git rev-parse --symbolic-full-name --remotes=\"*/$branch\"`" ]]; then
+	echo "There is not active upstream branch.  Exiting..."
+	exit 1
+fi
+
+touch /var/lock/update-tde-git-submodules
+
+PARENTDIR=$PWD
+echo "Working in $PARENTDIR"
 git pull
-git reset --hard HEAD
-git clean -d -x -f
+if [[ ! -z "`git status --porcelain --ignore-submodules`" ]]; then
+	git reset --hard HEAD
+	git clean -dxf
+fi
 
 exec 3< submodules
 while read <&3
@@ -26,25 +36,29 @@ do
 	if [[ $DIR2UPDATE != "" ]]; then
 		echo "Attempting to reset submodule $DIR2UPDATE"
 		cd $PARENTDIR/$DIR2UPDATE/..
-		while [[ ! -d .git ]]; do
-			cd ../
-		done
-		git submodule init
-		git submodule update
+		cd `git rev-parse --show-toplevel`
+		if [[ -z "`grep \"^Updated: $PWD$\" /var/lock/update-tde-git-submodules`" ]]; then
+			echo "Updated: $PWD" >>/var/lock/update-tde-git-submodules
+			git submodule init
+			git submodule update
+		fi
 		cd $PARENTDIR/$DIR2UPDATE
-		git reset --hard HEAD
-		git clean -d -x -f
-		git checkout master
+		if [[ ! -z "`git status --porcelain --ignore-submodules`" ]]; then
+			git reset --hard HEAD
+			git clean -dxf
+		fi
+		git checkout $branch
 		git pull
 		cd ..
-		while [[ ! -d .git ]]; do
-			cd ../
-		done
+		cd `git rev-parse --show-toplevel`
 		echo "Committing changes to $PWD"
-#		git commit -a -m "Reset submodule to latest HEAD"
-		git add $PARENTDIR/$DIR2UPDATE
-		git commit $PARENTDIR/$DIR2UPDATE -m "Reset submodule $DIR2UPDATE to latest HEAD"
-		git push origin master
+		if [[ ! -z "`git status --porcelain --ignore-submodules $PARENTDIR/$DIR2UPDATE`" ]]; then
+			git add $PARENTDIR/$DIR2UPDATE
+			git commit $PARENTDIR/$DIR2UPDATE -m "Reset submodule $DIR2UPDATE to latest HEAD"
+		fi
+		if [[ "`git rev-parse HEAD`" != "`git rev-parse origin/$branch`" ]]; then
+			git push origin HEAD
+		fi
 	fi
 done
 exec 3>&-
