Last week, I tried to get one of my private repositories to my workstation at the client site. It's quite common when you have no admin access to the workstation and proxy server with the authorization for internet access. First part is quite easy, you can find most of the DEV tools such as maven or git in a portable format. Now,  I'll tell you how to configure git with the corporate proxy.

Let's make sure that you have git installed and perform the initial configuration. Don't forget to substitute my name, email, and project with your values.

git --version
(out)git version 2.17.0.windows.1
git config --global user.email mikhailidim@gmail.com
git config --global user.name "Michael Mikhailidi"

My first try throws me an error similar to the one below.

git clone https://gitlab.com/mikhailidim/Json2Xml.git
(out)Cloning into 'Json2Xml'...
(out)fatal: unable to update url base from redirection:
(out)  asked for: https://gitlab.com/mikhailidim/Json2Xml.git/info/refs?service=git-upload-pack
(out)  redirect: http://proxy-server.domain:8080/plugin?target=Auth&reason=Auth&ClientID=<%some-internal-paraleters%>
(out) 

It gives you two useful hints:

  1. You are behind the proxy, and now you have the URL;
  2.  the error reason is authentication.

Git has global parameters for that too.  Add the parameter http.proxy  with your proxy URL and your domain account name. I also suppressed certificates validation. It's not exactly safe, but you don't have much choice if your proxy intercepts encrypted traffic.

git config --global http.proxy http://DOMAIN\username@proxy-server.domain:8080
git config --global http.sslverify false

As you may noticed I did not provided any passwords. But git will ask you when you start clone the repository for the first time.

git clone https://gitlab.com/mikhailidim/Json2Xml.git                       
(out)Cloning into 'Json2Xml'...                                                    
(out)Password for 'http://DOMAIN\username@proxy-server.domain:8080':         
(out)Username for 'https://gitlab.com': mikhailidim                                
(out)Password for 'https://mikhailidim@gitlab.com':                                
(out)remote: Enumerating objects: 142, done.                                       
(out)remote: Counting objects: 100% (142/142), done.                               
(out)remote: Compressing objects: 100% (65/65), done.                              
(out)remote: Total 142 (delta 27), reused 142 (delta 27)                           
(out)Receiving objects: 100% (142/142), 20.25 KiB | 1.12 MiB/s, done.              
(out)Resolving deltas: 100% (27/27), done.                                         

The first password is for the proxy authentication and then credentials for my GitLab account. Next time, it doesn't ask you any credentials, because they already stored in the Windows Password Manager Vault. Next time I would worry about passwords when the domain controller forces me to change it. You can find your credentials in the Windows Credential Manager. You can see my sample credentials on the screenshot below.

It works fine only if you use one account to access one server. If for some reasons you have multiple GitLab or GitHub accounts, it wouldn't work well. To enter credentials every time, reset git's credential helper git config --system --unset credential.helper.
You can restore the behavior with the command:
git config --global credential.helper manager


Special thanks to Mr. Gray for the great image.