After looking at various methods to test the access to a (private) git repository through ssh in bash (without cloning the repository), I've noticed I have some difficulties capturing the output of the probe.
For example, running:
#!/bin/bash
has_access="$(git ls-remote git@github.com:<some github username>/<some private repository>.git)"
echo "has_access=$has_access"
Returns:
ERROR: Repository not found.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
has_access=
Which demonstrates that the probe is effective at determining whether ssh does not have access, but it is not effective at capturing/storing this variable in a bash script.
Therefore, I would like to ask, how can I test whether ssh access into a (private) GitHub repository is available, or not, and store the (boolean) result in a bash variable (without cloning the repository)?