454

I have to use a git server without proper certificates, but I don't want to have to do

env GIT_SSL_NO_VERIFY=true git command

every single time I do a git operation. But I would also like to leave SSL enabled for other git repositories. Is there a way to make this local to a single repo?

3
  • 6
    Related: How can I make git accept a self signed certificate? Commented Sep 27, 2017 at 16:32
  • f15ijp.com/2012/08/… one of the best solutions i found Commented Mar 22, 2020 at 14:06
  • 1
    This is an awesome question because I didn't even know you could prepend this environment variable before the git command and have it bypass the expired certificate error. Commented Aug 16, 2022 at 15:21

12 Answers 12

864

You can do

git config http.sslVerify "false"

in your specific repo to disable SSL certificate checking for that repo only.

This won't work with git clone, since you don't yet have the local git repo to be able to set the flag in yet. Therefore in that case:

git -c http.sslVerify=false clone <path>
cd <directory>
git config http.sslVerify "false"
Sign up to request clarification or add additional context in comments.

14 Comments

git config --global http.sslVerify "false"
The --global should NOT be used because the OP has specifically requested that he only wants it for specific repos.
Note: Seems the --global option IS needed when a repo is NOT yet checked out (can't set options for a repo that doesn't exist yet locally). One can always turn it back on after.
I rollbacked the edit, since the question specifically didn't ask for this plus it is a bad idea to disable this globally for security reasons.
@TanveerBadar This is the proper way to clone a repository with SSL disabled, there is no need to disable SSL globally: "git -c http.sslVerify=false clone example.com/path/to/git" from stackoverflow.com/a/11622001/1710392
|
245

You can do as follows

For a single repo

git config http.sslVerify false

For all repo

git config --global http.sslVerify false

4 Comments

Why in the world you are using sudo at all? local repository doesn't need it, and user configuration is in $HOME (whatever that is on your system) so it doesn't need sudo either.
@ParthianShot cool im not serious, the above question and your answer will be useful for me as well as other users who have the same doubt, I have one more doubt also im not the administrator user, I tried the above code with out sudo but that does not worked for me with out sudo, so that im asking you in that case what should I do, if I should not use the sudo?
Are you using --system by default ? Otherwise as others have said, you should not use sudo
@HolaSoyEduFelizNavidad, When the OP said "for all repo," the OP meant "all repos for this user," not "all repos on the computer."
128

Like what Thirumalai said, but inside of the cloned repository and without --global. I.e.,

  1. GIT_SSL_NO_VERIFY=true git clone https://url
  2. cd <directory-of-the-clone>
  3. git config http.sslVerify false

{update 2024-04-04} Actually, there is even more simple way how to do the first step:

git -c http.sslVerify=false clone https://url

6 Comments

Good solution for cases when you could not lock global config file .gitconfig: Permission denied
If you have Permission denied on .gitconfig there is something seriously ske*ed with your system. Your $HOME should be available to you (which is where .gitconfig should be, shouldn't it?).
This is not actually my server. But thank you anyways. And I removed path from error message, actually on that server git is trying to access .gitconfig somewhere in /var/www/...
export GIT_SSL_NO_VERIFY=true
@ETech you don't want to do that: this makes all your git actions everywhere ignoring SSL (otherwise, using --global would be just fine). My solution is limited just to one repository.
|
34

If you have to disable SSL checks for one git server hosting several repositories, you can run :

git config --bool --add http.https://my.bad.server.sslverify false

This will add it to your user's configuration.

Command to check:

git config --bool --get-urlmatch http.sslverify https://my.bad.server 

(If you still use git < v1.8.5, run git config --global http.https://my.bad.server.sslVerify false)

Explanation from the documentation where the command is at the end, show the .gitconfig content looking like:

[http "https://my.bad.server"]
        sslVerify = false

It will ignore any certificate checks for this server, whatever the repository.

You also have some explanation in the code

1 Comment

This is the correct answer to the question, ie. disable SSL verification for a single remote server.
24

In particular if you need recursive clone

GIT_SSL_NO_VERIFY=true git clone --recursive https://github.com/xx/xx.git

Comments

20

If you are on a Windows machine and have the Git installed, you can try the below steps:

  1. Go to the folder of Git installation, ex: C:\Program Files (x86)\Git\etc
  2. Edit the file: gitconfig
  3. Under the [http] section, add the line: sslVerify = false

    [http]
      sslVerify = false
    

3 Comments

this also doesn't meet the question above where he says he doesn't want to affect other repos.
and It is really helpful when you can't run git commands! (i.g. having sourcetree on a windows virtual machine and placing the src folder in a UNC path in which built-in sorcetree terminal can't recognise!
For TortoiseGit users, you can edit this section into the local config file by doing a context-specific Settings update and selecting the option to edit local only
16

One more point ,apart from

git config --global http.sslVerify false

just setting the SSL verification to false ,you also have to have the key to clone the repository. something like this

git clone https://[email protected]/myorg/MYpro.git"

5edwerwe32434lcvghjjextracgecj is the token generated from github under settings/ Developer settings/

1 Comment

Works for me. On Windows OS. cmd as Administrator ` git config --system http.sslVerify false git config --global http.sslVerify false `
11

This question keeps coming up and I did not find a satisfying result yet, so here is what worked for me (based on a previous answer https://stackoverflow.com/a/52706362/1806760, which is not working):

My server is https://gitlab.dev with a self-signed certificate.

First run git config --system --edit (from an elevated command prompt, change --system to --global if you want to do it for just your user), then insert the following snippet after any previous [http] sections:

[http "https://gitlab.dev"]
        sslVerify = false

Then check if you did everything correctly:

> git config --type=bool --get-urlmatch http.sslVerify https://gitlab.dev
false

Comments

8

There is an easy way of configuring GIT to handle your server the right way. Just add an specific http section for your git server and specify which certificate (Base64 encoded) to trust:

~/.gitconfig

[http "https://repo.your-server.com"]
# windows path use double back slashes
#  sslCaInfo = C:\\Users\\<user>\\repo.your-server.com.cer
# unix path to certificate (Base64 encoded)
sslCaInfo = /home/<user>/repo.your-server.com.cer

This way you will have no more SSL errors and validate the (usually) self-signed certificate. This is the best way to go, as it protects you from man-in-the-middle attacks. When you just disable ssl verification you are vulnerable to these kind of attacks.

https://git-scm.com/docs/git-config#git-config-httplturlgt

1 Comment

Instead of editing this file manually, can we use a git config --global command to do the same?
5

This works for me:

git init
git config --global http.sslVerify false
git clone https://myurl/myrepo.git

Comments

1

On Linux, if you call this inside the git repository folder:

git config http.sslVerify false

this will add sslVerify = false in the [http] section of the config file in the .git folder, which can also be the solution, if you want to add this manually with nano .git/config:

...
[http]
  sslVerify = false

Comments

-2

for windows, if you want global config, then run

git config --global http.sslVerify false

2 Comments

OP asked for specific repos explicitly
that's still useful information

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.