Merge pull request #16196 from yongtang/15957-branch-switch

Fix issue of branch switching not working with bazel
diff --git a/third_party/git/git_configure.bzl b/third_party/git/git_configure.bzl
index 47e2125..8e2839b 100644
--- a/third_party/git/git_configure.bzl
+++ b/third_party/git/git_configure.bzl
@@ -38,6 +38,11 @@
       Label("@org_tensorflow//tensorflow/tools/git:gen_git_source.py"))
   generated_files_path = repository_ctx.path("gen")
 
+  r = repository_ctx.execute(
+      ["test", "-f", "%s/.git/logs/HEAD" % tensorflow_root_path])
+  if r.return_code == 0:
+    unused_var = repository_ctx.path(Label("//:.git/HEAD")) # pylint: disable=unused-variable
+
   result = repository_ctx.execute([
       _get_python_bin(repository_ctx),
       python_script_path, "--configure", tensorflow_root_path,