【问题标题】:finding the name of git branch from remote server从远程服务器查找 git 分支的名称
【发布时间】:2017-12-28 23:19:08
【问题描述】:

我正在尝试使用 shell 脚本在远程服务器上查找 git 分支的名称。我把下面的命令放在了bin目录下的一个脚本里。

git symbolic-ref --short HEAD

当我在另一台机器上使用ssh 执行脚本时

ssh -i keyfile.pem user@ipaddress 'bash -s' /path/to/the/script

我收到一个错误

fatal: Not a git repository (or any of the parent directories): .git

不确定我在哪里做错了。任何帮助将不胜感激。

谢谢。

【问题讨论】:

  • cd /path/to/your/git/repo 然后git branch --remote 列出远程分支。

标签: linux git bash shell ssh


【解决方案1】:

您对 git 的调用使用了错误的工作目录(可能是您的主目录)。

在你的脚本中,要么 cd 到包含 git 目录的路径,要么用 git 指定 -C 选项:

git -C /path/to/git/checkout symbolic-ref --short HEAD

-C 选项允许您覆盖工作目录:

   -C <path>
       Run as if git was started in <path> instead of the current working directory. When
       multiple -C options are given, each subsequent non-absolute -C <path> is interpreted
       relative to the preceding -C <path>.

【讨论】:

  • 是的!在脚本中添加 -c 和路径选项有效!非常感谢@Markus Kasten
  • 很高兴听到!如果对您有帮助,可以通过选择此答案作为已接受的答案来结束此问题吗?
猜你喜欢
  • 2023-04-10
  • 2015-12-07
  • 2018-09-12
  • 2012-04-21
  • 2021-09-09
  • 1970-01-01
  • 1970-01-01
  • 2012-10-20
  • 1970-01-01
相关资源
最近更新 更多