2

I have a list of directories where I want to run git pull

Some of these may be empty.

When I run git pull on it, I get this error:

Your configuration specifies to merge with the ref 'master'
from the remote, but no such ref was fetched.

and an exit code of 1

I have my script to exit if any command fails.

Is it possible to detect if it failed due to this error? Or any other way to pull which doesn't error out on empty repositories?

Edit: .git/config

git:(master) cat .git/config 
[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url = <git repo url>
[branch "master"]
    remote = origin
    merge = refs/heads/master
user1527166
  • 3,229
  • 5
  • 26
  • 26

2 Answers2

1

This is taken from here

To clone an empty repo at path,

  1. Keep at ~/git/onefile a non-bare git repo containing one innocuous
    file such as .gitignore. (Alternatively, create such a repo
    dynamically.)
  2. (cd ~/git/onefile; git push path master)
  3. git clone -o name path

In other words, don't attempt to clone the empty repo, but rather after creating it, push to it a simple repo containing one innocuous file. Then it is no longer empty and can be cloned.

Community
  • 1
  • 1
Rorchackh
  • 2,113
  • 5
  • 22
  • 38
1

You can test it on the remote reference existance. For example, the master reference does not yet exist after init, so in the windows batch script it would be something like this:

git ls-remote -h --exit-code myrepo master > nul && (
  git pull myrepo master
)
Andry
  • 2,273
  • 29
  • 28