Reputation: 541
i am trying to find the name of git branch on remote server using a shell script. I put the following command in a script under the bin directory.
git symbolic-ref --short HEAD
When I execute the script using ssh
from another machine
ssh -i keyfile.pem user@ipaddress 'bash -s' /path/to/the/script
I get an error
fatal: Not a git repository (or any of the parent directories): .git
Not sure where I am doing wrong. Any help would be appreciated.
Thanks.
Upvotes: 2
Views: 636
Reputation: 1170
Your call to git is using the wrong working directory (likely your home directory).
In your script, either cd to the path containing the git directory or specify the -C
option with git:
git -C /path/to/git/checkout symbolic-ref --short HEAD
The -C
option allows you to overwrite the working directory:
-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>.
Upvotes: 3