How to Clone a GitLab Repository with a Self-Signed Certificate
Source: Dev.to
Problem Overview
When working with a GitLab instance that uses a self‑signed SSL certificate, cloning over HTTPS often fails with an error such as:
fatal: unable to access 'https://gitlab.example.com/group/project.git/':
server certificate verification failed. CAfile: none CRLfile: none
Git does not trust self‑signed certificates by default, so HTTPS connections are rejected unless you explicitly tell Git to trust the certificate.
Export the Self‑Signed Certificate
Using Chrome
-
Open your GitLab URL in Chrome:
https://gitlab.example.com -
Click the lock icon → Connection is secure → Certificate is valid.
-
Go to the Details tab → Export….
-
Save the certificate as
gitlab-selfsigned.crtin a permanent location:- Windows:
C:\certs\gitlab-selfsigned.crt - Linux/macOS:
/home/username/certs/gitlab-selfsigned.crt
- Windows:
Using Firefox
- Open
about:preferences#privacyin Firefox. - Scroll to Certificates → click View Certificates.
- In the Servers tab, locate
gitlab.example.com, select it, then click Export…. - Save the file as
gitlab-selfsigned.crt.
Using OpenSSL (any platform)
openssl s_client -connect gitlab.example.com:443 -showcerts 2>/dev/null \
| openssl x509 -outform PEM > gitlab-selfsigned.crt
The command fetches the certificate directly from GitLab and writes it to gitlab-selfsigned.crt in the current directory.
Configure Git to Trust the Certificate
# Windows example
git config --global http.sslCAInfo "C:/certs/gitlab-selfsigned.crt"
# Linux/macOS example
git config --global http.sslCAInfo "/home/username/certs/gitlab-selfsigned.crt"
Verify the Setting
git config --global --get http.sslCAInfo
The command should output the path you just configured.
Clone the Repository Over HTTPS
git clone https://gitlab.example.com/group/project.git
With the certificate trusted, the clone should succeed without SSL errors.
Use SSH as an Alternative (No Certificate Issues)
-
Generate an SSH key (if you don’t have one):
ssh-keygen -t ed25519 -C "your_email@example.com" -
Add the public key (
~/.ssh/id_ed25519.pub) to GitLab:
User Settings → SSH Keys → Add Key. -
Clone via SSH:
git clone git@gitlab.example.com:group/project.git
Temporarily Disabling SSL Verification (Not Recommended)
git config --global http.sslVerify false
⚠️ Warning: Disabling verification is insecure and exposes you to MITM attacks. Use it only as a short‑term troubleshooting step, never in production.
Configuring Git in PyCharm
- Open File → Settings → Version Control → Git.
- Verify the Path to Git executable points to the Git you configured above.
- Click Test to ensure the executable works.
- If you rely on HTTPS, make sure the same
http.sslCAInfosetting is applied to the Git used by PyCharm (or switch to SSH).
Recommended Workflow for Self‑Signed GitLab
- Export the self‑signed certificate (Chrome, Firefox, or OpenSSL).
- Configure Git globally with
http.sslCAInfopointing to the exported.crtfile. - Clone repositories over HTTPS, or use SSH to avoid certificate handling altogether.
- Never leave
http.sslVerifydisabled permanently.