Configure git to use IPv4 instead of IPv6 by default

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

  • How can I email someone a git repository?
  • How to make travis-ci work with a local git branch instead of a specific commit?
  • Is it possible to merge disjoint Git repos that were imported from the same CVS source?
  • Running git-instaweb on boot
  • Git won't add modified file
  • How do I fork multiple projects into one repository with git?
  • Why does Git remember and use a conflict resolution from an aborted rebase without asking me?
  • How do you delete a git tag and propagate said delete through git pull to others?
  • How to get Gerrit: Code Review to output email diffs on successful commit
  • Egit working directory vs. projects in Eclipse
  • Git error: Unable to append to .git/logs/refs/remotes/origin/master: Permission denied
  • Setting up CI with TeamCity with Git & NAnt
  • 3 Solutions collect form web for “Configure git to use IPv4 instead of IPv6 by default”

    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.

    With git 2.8 (March 2016), you can force git fetch/push/clone to use IPV4 or IPV6.

    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.

    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
    
    Git Baby is a git and github fan, let's start git clone.