title: How to resolve stderr: fatal: Not a valid object name HEAD in jenkins?
body: <p>I am trying to get the latest code from git through Jenkins. Everytime I do so I get the following error. I have followed in through a few links on stackoverflow foe this but none of them seem to resolve the issue. </p>
  
  <ol>
  <li>Tried deleting the entire workspace and then run again. It throws the same error.</li>
  <li>Included git reset --hard in the Execute shell build option</li>
  </ol>
  
  <p>Here is the error.</p>
  
  <pre><code>Checking out Revision bc304892eadfaaf7338fa6e5f370137555d7cfd9 (refs/remotes/origin/master)
   &gt; C:\Program Files\Git\bin\git.exe config core.sparsecheckout # timeout=10
   &gt; C:\Program Files\Git\bin\git.exe config core.sparsecheckout true # timeout=10
   &gt; C:\Program Files\Git\bin\git.exe read-tree -mu HEAD # timeout=10
  Command "C:\Program Files\Git\bin\git.exe read-tree -mu HEAD" returned status code 128:
  stdout: 
  stderr: fatal: Not a valid object name HEAD
  
   &gt; C:\Program Files\Git\bin\git.exe checkout -f bc304892eadfaaf7338fa6e5f370137555d7cfd9
  FATAL: Could not checkout bc304892eadfaaf7338fa6e5f370137555d7cfd9
  hudson.plugins.git.GitException: Could not checkout bc304892eadfaaf7338fa6e5f370137555d7cfd9
      at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$8.execute(CliGitAPIImpl.java:1907)
      at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler$1.call(RemoteGitImpl.java:152)
      at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler$1.call(RemoteGitImpl.java:145)
      at hudson.remoting.UserRequest.perform(UserRequest.java:120)
      at hudson.remoting.UserRequest.perform(UserRequest.java:48)
      at hudson.remoting.Request$2.run(Request.java:326)
      at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:68)
      at java.util.concurrent.FutureTask.run(Unknown Source)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
      at hudson.remoting.Engine$1$1.run(Engine.java:62)
      at java.lang.Thread.run(Unknown Source)
      at ......remote call to odesk.delta.04(Native Method)
      at hudson.remoting.Channel.attachCallSiteStackTrace(Channel.java:1416)
      at hudson.remoting.UserResponse.retrieve(UserRequest.java:220)
      at hudson.remoting.Channel.call(Channel.java:781)
      at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler.execute(RemoteGitImpl.java:145)
      at sun.reflect.GeneratedMethodAccessor434.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:483)
      at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler.invoke(RemoteGitImpl.java:131)
      at com.sun.proxy.$Proxy51.execute(Unknown Source)
      at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1060)
      at hudson.scm.SCM.checkout(SCM.java:485)
      at hudson.model.AbstractProject.checkout(AbstractProject.java:1276)
      at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:607)
      at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:86)
      at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:529)
      at hudson.model.Run.execute(Run.java:1738)
      at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
      at hudson.model.ResourceController.execute(ResourceController.java:98)
      at hudson.model.Executor.run(Executor.java:410)
  Caused by: hudson.plugins.git.GitException: Command "C:\Program Files\Git\bin\git.exe checkout -f bc304892eadfaaf7338fa6e5f370137555d7cfd9" returned status code 128:
  stdout: 
  stderr: error: Sparse checkout leaves no entry on working directory
  
      at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1640)
      at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$500(CliGitAPIImpl.java:62)
      at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$8.execute(CliGitAPIImpl.java:1899)
      at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler$1.call(RemoteGitImpl.java:152)
      at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler$1.call(RemoteGitImpl.java:145)
      at hudson.remoting.UserRequest.perform(UserRequest.java:120)
      at hudson.remoting.UserRequest.perform(UserRequest.java:48)
      at hudson.remoting.Request$2.run(Request.java:326)
      at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:68)
      at java.util.concurrent.FutureTask.run(Unknown Source)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
      at hudson.remoting.Engine$1$1.run(Engine.java:62)
      at java.lang.Thread.run(Unknown Source)
  Finished: FAILURE
  </code></pre>