如何完全静音 git ls-remote?

der*_*ugo 5 bash git

我正在编写一个迁移 bash 脚本,用于使用 gitLFS 将存储库从 Github 迁移到 Gitlab。

其中一步是检查源存储库和目标存储库是否存在。

在我的搜索中,我发现这git ls-remote非常适合。

对于我的脚本,我想使命令的输出静音(脚本本身稍后会检查它),所以我使用$> /dev/null

git ls-remote -q <URL to repository> $> /dev/null
Run Code Online (Sandbox Code Playgroud)

来自man git ls-remote

-q, --quiet: 不将远程 URL 打印到 stderr。

成功后我没有得到任何输出并git ls-remote退出0

失败时(可能是由于提供不正确的凭据或未找到存储库引起的),它会退出,128但我总是看到此输出

remote: Invalid username or password.
fatal: Authentication failed for '<URL to repository>'
Run Code Online (Sandbox Code Playgroud)

或者

remote: Repository not found.
fatal: repository '<URL to repository>' not found
Run Code Online (Sandbox Code Playgroud)

怎样才能彻底沉默呢git ls-remote

Fél*_*ien 5

如果你想将所有输出和 stderr 重定向到 /dev/null 你必须替换

git ls-remote -q <URL to repository> $> /dev/null
Run Code Online (Sandbox Code Playgroud)

经过

git ls-remote -q <URL to repository> &> /dev/null
Run Code Online (Sandbox Code Playgroud)

&代替$