diff --git a/git_deploy.install b/git_deploy.install
index eb66c85..1ffa665 100644
--- a/git_deploy.install
+++ b/git_deploy.install
@@ -11,3 +11,10 @@ function git_deploy_requirements($phase) {
   }
   return $requirements;
 }
+
+/**
+ * Implements hook_uninstall().
+ */
+function git_deploy_unisntall() {
+  variable_del('git_deploy_path_to_git');
+}
diff --git a/git_deploy.module b/git_deploy.module
index 661dc7e..cc06f6f 100644
--- a/git_deploy.module
+++ b/git_deploy.module
@@ -23,13 +23,29 @@ function git_deploy_system_info_alter(&$info, $file, $type = NULL) {
     $directory = dirname($file->uri);
     // Check whether this belongs to core. Speed optimization.
     if (substr($directory, 0, strlen($type)) != $type) {
-      while ($directory && !is_dir("$directory/.git")) {
-        $directory = substr($directory, 0,  strrpos($directory, '/'));
+      while ($directory && !file_exists("$directory/.git")) {
+        $directory = substr($directory, 0, strrpos($directory, '/'));
       }
       $git_dir = "$directory/.git";
+      // Check if this is a git submodule architecture.
+      if (is_file($git_dir)) {
+        $git_config = file($git_dir);
+        foreach ($git_config as $config_line) {
+          if (stristr($config_line, 'gitdir: ') !== FALSE) {
+            $git_dir = trim(str_replace('gitdir: ', '', $config_line));
+            // Check if this is a relative path.
+            if (!is_dir($git_dir)) {
+              $real_module_dir = realpath(DRUPAL_ROOT . '/' . $directory);
+              $git_dir = realpath($real_module_dir . '/' . $git_dir);
+            }
+            break;
+          }
+        }
+      }
+
       // Theoretically /.git could exist.
       if ($directory && is_dir($git_dir)) {
-        $git = "git --git-dir $git_dir";
+        $git = escapeshellarg(variable_get('git_deploy_path_to_git', 'git')) . ' --git-dir ' . escapeshellarg($git_dir);
         // Find first the project name based on fetch URL.
         // Eat error messages. >& is valid on Windows, too. Also, $output does
         // not need initialization because it's taken by reference.
