Unable to connect to a repository with an "Unknown option: -c" error
Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.
Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Summary
Unable to connect to a repository in Bamboo as it fails with an Unknown option: -c error:
2023-02-07 12:13:47,366 INFO [http-nio-8085-exec-5] [RepositoryResource] Failed to connect to repository (type: GitHub repository, location: https://github.com/project/repository.git, time: 15.05 ms, errors: [Unknown option: -c
usage: git [--version] [--exec-path[=GIT_EXEC_PATH]] [--html-path]
The error can also be seen when performing repository checkout on Bamboo builds:
simple 28-Aug-2017 14:38:02 Creating local git repository in '/home/bamboo/bamboo-home/xml-data/build-dir/PROJ-PLAN-JOB1/.git'.
simple 28-Aug-2017 14:38:02 error: unknown switch `c'
simple 28-Aug-2017 14:38:02 usage: git clone [options] [--] <repo> [<dir>]
[...]
Environment
- All supported versions of Bamboo.
- Older version of Git (<2.x) on the main Bamboo server or on its agents.
Diagnosis
When adding a repository in Bamboo, even though the list of repositories can be loaded and the repository saved, when clicking on the Test connection button, the following error appears:
The following can be seen on the BAMBOO_HOME/logs/atlassian-bamboo.log file:
2023-02-07 12:13:47,351 INFO [http-nio-8085-exec-5] [RepositoryResource] Testing connection to repository (type: GitHub repository, location: https://github.com/project/repository.git\)
2023-02-07 12:13:47,366 INFO [http-nio-8085-exec-5] [RepositoryResource] Failed to connect to repository (type: GitHub repository, location: https://github.com/project/repository.git, time: 15.05 ms, errors: [Unknown option: -c
usage: git [--version] [--exec-path[=GIT_EXEC_PATH]] [--html-path]
[-p|--paginate|--no-pager] [--no-replace-objects]
[--bare] [--git-dir=GIT_DIR] [--work-tree=GIT_WORK_TREE]
[--help] COMMAND [ARGS]])
If the repository is saved without testing the connection, Bamboo builds using that repository will fail as well.
You can run the following command on the Bamboo machine terminal (and on the remote agents) with the same user account that runs Bamboo to check which version is being used:
git --version
Cause
This is caused by an older version of Git being used, which didn't include the -c option Bamboo uses when configuring repositories. Bamboo 7.1 and newer versions support Git version 2.8 or newer, as per the Supported Platforms documentation. Bamboo 5.10 through 7.0 only supports Git version 1.8.1.5 or newer.
Solution
Please upgrade Git to a more recent version that is supported by Bamboo, such as 2.3x. The same needs to be done on any remote agents using older versions.