Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configure git to use IPv4 instead of IPv6 by default

Tags:

git

ipv6

ipv4

Checking the environment variables and also HTTP configuration options does not reveal something. Is there a way to do this?

like image 366
nobeh Avatar asked Feb 10 '14 07:02

nobeh


People also ask

How do I use IPv4 instead of IPv6?

The preference of IPv4 over IPv6 can be enabled by changing the registry key DisabledComponents with the registry value Hex 0x20 (Dec 32). Copy Paste and run in command prompt as admin. The registration method to favor Windows IPv4 over IPv6 is a general, but less system-compliant solution.

Can I change from IPv4 to IPv6?

To convert Internet Protocol 4 (IPv4) to Internet Protocol 6 (IPv6), perform the following steps. Open the tool: IPv4 to IPv6 converter. Enter any valid IPv4 address, and click on the "Convert to IPv6" button. The tool will process your request and provide you the converted IPv6 address.


3 Answers

The more generic solution (that also works for BSD) is to edit the global /etc/ssh/ssh_config or per-user ~/.ssh/config and add/replace the entry:

AddressFamily any 

with

AddressFamily inet

You can also set this for just a single host:

Host example.com
    AddressFamily inet
like image 63
Anthony C Howe Avatar answered Oct 12 '22 20:10

Anthony C Howe


With git 2.8 (March 2016), you can force git fetch/push/clone to use IPV4 or IPV6.
(for git pull, see below Git 2.16, Q1 2018)

See commit c915f11 (03 Feb 2016) by Eric Wong (ele828).
(Merged by Junio C Hamano -- gitster -- in commit e84d5e9, 24 Feb 2016)

connect & http: support -4 and -6 switches for remote operations

Sometimes it is necessary to force IPv4-only or IPv6-only operation on networks where name lookups may return a non-routable address and stall remote operations.

-4, --ipv4:

Use IPv4 addresses only, ignoring IPv6 addresses.

-6; --ipv6:

Use IPv6 addresses only, ignoring IPv4 addresses.


Update Git 2.16 (Q1 2018): Contrary to the documentation, "git pull -4/-6 other-args" did not ask the underlying "git fetch" to go over IPv4/IPv6, which has been corrected.

See commit ffb4568 (19 Nov 2017) by Shuyu Wei (``).
(Merged by Junio C Hamano -- gitster -- in commit c2b6135, 27 Nov 2017)


With Git 2.29 (Q4 2020), "git fetch --all --ipv4/--ipv6(man)" forgot to pass the protocol options to instances of the "git fetch" that talk to individual remotes, which has been corrected.

See commit 4e735c1 (15 Sep 2020) by Alex Riesen (ar-cetitec).
(Merged by Junio C Hamano -- gitster -- in commit 6854689, 22 Sep 2020)

fetch: pass --ipv4 and --ipv6 options to sub-fetches

Signed-off-by: Alex Riesen

The options indicate user intent for the whole fetch operation, and ignoring them in sub-fetches (i.e. "--all" and recursive fetching of submodules) is quite unexpected when, for instance, it is intended to limit all of the communication to a specific transport protocol for some reason.

like image 40
VonC Avatar answered Oct 12 '22 21:10

VonC


In 99% of cases, you should not be doing this. The real answer to the question is fix your IPv6 connection.

Failing that, you can edit /etc/gai.conf to prefer IPv4 over IPv6. gai.conf modifies the behaviour of getaddrinfo(), which almost all IPv6–supporting applications use to resolve hostnames.

Almost all systems ship with a copy of /etc/gai.conf within their glibc or libc package. If it is missing from /etc, usually I find a template copy is lurking somewhere within /usr/share/doc, for you to copy into /etc and modify accordingly.

like image 12
Jeremy Visser Avatar answered Oct 12 '22 21:10

Jeremy Visser