416

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

12 Answers 12

803

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"
14
  • 103
    git config --global http.sslVerify "false"
    – sgohl
    Jul 26, 2017 at 12:48
  • 67
    The --global should NOT be used because the OP has specifically requested that he only wants it for specific repos. Sep 6, 2017 at 9:29
  • 20
    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. Nov 29, 2017 at 18:58
  • 5
    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.
    – Étienne
    Aug 29, 2018 at 14:23
  • 27
    @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
    – Étienne
    Dec 17, 2019 at 16:00
223

You can do as follows

For a single repo

git config http.sslVerify false

For all repo

git config --global http.sslVerify false
7
  • 7
    This will disable SSL verification for all repositories. The original question was about making it local to a single repository. Dec 20, 2013 at 22:29
  • 5
    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.
    – mcepl
    Jul 30, 2015 at 8:25
  • @ParthianShot if they are not the admin user how they can use this with out sudo? Feb 5, 2016 at 8:40
  • 1
    @Thirumalaimurugan Are you serious right now? sudo should only be used when you actually need root to do something. Like installing new software, modifying important system files, reformatting drives, reconfiguring the network, managing services... There was nothing in this guy's question to imply that he needed root to do anything. If you're an administrator, you should be running most of your commands- including those commands which change your configuration- without sudo most of the time. Feb 5, 2016 at 14:50
  • 2
    @HolaSoyEduFelizNavidad, When the OP said "for all repo," the OP meant "all repos for this user," not "all repos on the computer."
    – vy32
    Aug 3, 2018 at 14:30
119

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
6
  • Good solution for cases when you could not lock global config file .gitconfig: Permission denied
    – gorodezkiy
    Jul 29, 2015 at 23:03
  • 1
    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?).
    – mcepl
    Jul 30, 2015 at 8:27
  • 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/...
    – gorodezkiy
    Jul 30, 2015 at 19:36
  • 4
    export GIT_SSL_NO_VERIFY=true
    – ETech
    Oct 5, 2017 at 13:32
  • 1
    @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.
    – mcepl
    Oct 6, 2017 at 9:23
25

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
  • 1
    This is the correct answer to the question, ie. disable SSL verification for a single remote server. Apr 7, 2022 at 14:13
24

In particular if you need recursive clone

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

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
  • 1
    this also doesn't meet the question above where he says he doesn't want to affect other repos.
    – bryanmac
    Feb 4, 2015 at 23:19
  • 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! Oct 3, 2015 at 15:44
  • 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 Aug 7, 2016 at 14:11
13

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
  • Works for me. On Windows OS. cmd as Administrator ` git config --system http.sslVerify false git config --global http.sslVerify false `
    – GSD.Aaz
    May 16, 2022 at 10:06
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
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

5

This works for me:

git init
git config --global http.sslVerify false
git clone https://myurl/myrepo.git
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
-1

for windows, if you want global config, then run

git config --global http.sslVerify false
1
  • 2
    OP asked for specific repos explicitly
    – malat
    May 25, 2016 at 10:19

Not the answer you're looking for? Browse other questions tagged or ask your own question.