1

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
4

2 回答 2

1

这是取自这里

要在path克隆一个空仓库,

  1. ~/git/onefile中保留一个非裸 git 存储库,其中包含一个无害
    文件,例如 .gitignore。(或者,
    动态创建这样的存储库。)
  2. (cd ~/git/onefile; git push path master)
  3. git clone -o名称 路径

换句话说,不要试图克隆空的 repo,而是在创建它之后,向它推送一个包含一个无害文件的简单 repo。然后它不再是空的,可以克隆了。

于 2012-10-31T12:41:53.097 回答
1

您可以在远程参考存在上对其进行测试。例如,主引用在 init 之后还不存在,所以在 windows 批处理脚本中它会是这样的:

git ls-remote -h --exit-code myrepo master > nul && (
  git pull myrepo master
)
于 2017-07-30T02:16:57.107 回答