When pushing branches and tags, get error: cannot spawn git: no such file or directory

10,870

Solution 1

As this comment led to a solution (see edit at end of question), here it is reposted as an answer:

Are you using MSysGit? This has been known to happen if you have a large number of tags. See This post.

Solution 2

I also has this problem due to a large number of tags when using git on Windows. I solved it by making a batch script that pushed some of the tags one at a time until the number of tags was a bit below 500. Then I was able to make a git push that took some time to complete, but worked.

So you pretty much just open notepad, write git push origin <yourtagname> for each tag you want to push, one per line, save it as blabla.bat in your git repository folder and run it. It is even easier if you just copy all the file names from the tag folder .git\refs\tags and do some replacement magic to add git push origin in front of each file name.

Solution 3

According to this post, the underlying issue is that git misbehaves if installed to a directory with spaces in the path. That's consistent with my environment where I encountered the error and with the error message reported.

I guess that behavior comes as no surprise given that git was originally written by the author of Linux. The typical workaround seems to be to use an operating system that's hostile to spaces in path names.

Solution 4

I faced the same problem ( cannot spawn git: no such file or directory ) when tried to push on stash/bitbucket git server some large project exported from TFS (on local pc git folder). There was a single branch and a lot of tags (3K+ tags). The problem appears on pushing all tags command, while pushing a single tag works ok. I am using GitExtensions (msysgit based) and connection to remote was http.

The solution was wound suddenly: I re-configured my git to use SSH connection to remote instead of http and this miraculously solve the problem: pushing all tags went successful.

Share:
10,870
kevinmm
Author by

kevinmm

Updated on June 04, 2022

Comments

  • kevinmm
    kevinmm almost 2 years

    I have an existing, bare, Git repository created from importing our source and history from CVS. I make a mirror, using:

    git clone --mirror git://aserver.adomain.com/myrepo
    

    Then, I want to push all branches and tags to our internal Git repo host, but the push doesn't seem to see the bare repository as a Git repo.

    I have tried the following:

    git clone --mirror git://aserver.adomain.com/myrepo
    git remote set-url origin http://[email protected]/project/myrepo.git
    git push origin
    

    which results in:

    $ git push origin
    Password for 'xxxx':
    error: cannot spawn git: No such file or directory
    

    or I try:

    $ git remote rm origin
    Note: Some branches outside the refs/remotes/ hierarchy were not removed;
    to delete them, use:
      ...a whole lot of branches...
    
    user@SOMEMACHINE /some/path/myrepo.git (BARE:master)
    $ ls
    HEAD  config  description  hooks  info  objects  packed-refs  refs
    
    user@SOMEMACHINE /some/path/myrepo.git (BARE:master)
    $ git branch -a
      ...a whole lot of local branches...
    
    user@SOMEMACHINE /some/path/myrepo.git (BARE:master)
    $ git remote add mygithost http://[email protected]/project/myrepo.git
    
    user@SOMEMACHINE /some/path/myrepo.git (BARE:master)
    $ git push --all mygithost
    Password for 'xxxx':
    error: cannot spawn git: No such file or directory
    

    What is the meaning of "cannot spawn git"?

    How can I push a bare repo, with all branches, to an empty existing one?

    I have googled several possibilities and reviewed several SO issues, but I don't see a solution to this problem. Clearly, my understanding of this process is flawed.

    Update

    I guess my understanding was not flawed. The error somehow misled me to think that there was something wrong with the bare repository, as I could clone and push branch by branch just fine from "regular" clones.

    As it turns out, this is a bug in MSysGit. I moved to Linux because retaining all of the history was a requirement, in my case. I couldn't simply remove branches and tags, as these needed to be pushed to the empty remote repo. So, the following did work:

    $ git remote rm origin
    $ git clone --mirror git://aserver.adomain.com/myrepo
    $ cd /some/path/myrepo.git
    $ git remote add mygithost http://[email protected]/project/myrepo.git
    $ git push --all mygithost
    $ git push --tags mygithost
    
  • kevinmm
    kevinmm about 11 years
    Oddly enough, I believe I ran into another "large number of tags" issue, when trying to clone using http. The clone worked fine with the git protocol, but from http, it resulted in: error: could not spawn git: no such file or directory. I was using 1.7.8 and moving to 1.8.1 resolved this. I couldn't find the issues in the MSysGit bug tracker, but maybe the "tag problems" have been resolved?
  • rob
    rob almost 10 years
    Thanks! I ran into the same error ("error: cannot spawn git: No such file or directory") and even upgrading to the latest msysgit (1.9.2) didn't fix it, but running the the same command, git push kiln --tags, from my Linux VM did the trick.
  • it3xl
    it3xl about 9 years
    No! Not only. I reinstalled the git and the trouble persists. Tags amount maybe.