Date: May 8, 2024 /  Author: Ralf Eichinger

GIT behind Proxy

How to configure GIT to use a proxy (depending on current directory)

Homepage: https://git-scm.com/docs/git-config

You successfully installed GIT following our previous post GIT Basics.

Now you want to configure a proxy for accessing git repositories depending on the location of the git repositories.

Let’s say you have git repositories

  1. accessible without proxy (inhouse)
  2. accessible only through proxy (external)

To make git configuration for proxy depending on case 1) and 2) we checkout inhouse-repositories into a different directory than the external-repositories, e.g.

  • inhouse repositories into “C:/Laufwerk_D/projects/”
  • external repositories into “C:/Laufwerk_D/projects-ext/”

Depending on the directory we can include different gitconfig-files: for 1) without proxy and for 2) with proxy configuration.

WARNING: If you mapped a directory to a drive on a windows machine with e.g. subst D: <mapped directory> you have to use the underlying directory in the gitdir path! Just change into checked out repository and get your underlying directory by issuing git rev-parse --show-toplevel.

Configuration

Edit the .gitconfig file in your user’s home directory:

[includeIf "gitdir/i:C:/Laufwerk_D/projects/"]
	path = .gitconfig-inhouse
[includeIf "gitdir/i:C:/Laufwerk_D/projects-ext/"]
	path = .gitconfig-external

Create the both environment specific gitconfig-files:

File .gitconfig-inhouse, e.g.:

[user]
	name = Your Name
	email = ****@*****
[credential]
	helper = store
[meta]
	isLocalConfig = true

File .gitconfig-external, e.g.:

[user]
	name = Your Name
	email = ****@****
	signingkey = 7A25ASDD8FFBBAA6EF25AA51DD9C75A0D9904A0AF64
[core]
	isExternalConfig = true
[http]
	proxy = http://<ip-address>:<port>
[https]
	proxy = http://<ip-address>:<port>
	sslVerify = false

The signingkey is optional, if you want sign your commits with a GPG key. See https://docs.github.com/en/authentication/managing-commit-signature-verification/about-commit-signature-verification

Test

Make sure you are actually in a git repo inside the folder (e.g. C:/Laufwerk_D/projects-ext/my-project-repo), otherwise it will return the default values!

If you do not have a repository, yet, create or clone one.

If cloning does not work, because you need for example the proxy settings, defined in the corresponding include file, you can specify URL-specific proxy settings in .gitconfig:

[http "https://github.com/"]
   proxy = <ip-address>:<port>
[https "https://github.com/"]
    proxy = <ip-address>:<port>
[git "https://github.com/"]
    proxy = <ip-address>:<port>
[url "https://github.com/"]
    insteadOf = git://github.com/
 Tags:  topics development tools git

Previous
⏪ Installation and Configuration of Visual Studio Code

Next
Debian Linux 12 auf einem Strato VPS (Virtual Private Server) ⏩