简体   繁体   中英

cloning a corporate git repo

I normally use git behind a proxy. Hence I have those set in my global config. git config -l --global has entries for http & https.

However for accessing the corporate git repo, I have to unset the global proxy and then clone.

Is there an alternative where I don't have to change the global settings like this?

Have you tried setting environment variables for http_proxy , https_proxy , and no_proxy ?

Take a look at these two answers here on SO:

Only use a proxy for certain git urls/domains?

How to temporarily disable git http proxy

The best way is to write a batch file with setting of proxy and unsetting of proxy and run it through.

Configure Git proxy using git Proxy Command

git config --global http.proxy http://username:password@proxy.server.com:8080
git config --global https.proxy http://username:password@proxy.server.com:8080

Replace username with your proxy username
Replace password with your proxy password
Replace proxy.server.com with the proxy domain URL.
Replace 8080 with the proxy port no configured on the proxy server.

How to Remove Git Proxy? Remove Git Proxy CommandPHP

git config --global --unset http.proxy
git config --global --unset https.proxy

How to Verify Currently Set Git Proxy?

git config --global --get http.proxy
git config --global --get https.proxy

Git is written in mind with 3 different config files:

  • System wide config
  • User wide config
  • Second user wide config
  • Local repo config

Notice: the following tutorial assumes that you have your proxy configuration have saved inside you global or user specific config, like the OP has.

Removing Proxy from our already existing repo

We can remove the proxy inside our existing corporate repositories by simple cd-ing to the directory and running:

git config --local --add http.proxy ""

This will set the proxy to an empty string, what git uses to specify that a direct communication is made.

Cloning a repo without a proxy

This situation is trickier because we need to Unset the proxy, clone, and reconfigure the proxy. For this purpose, we can write a simple bash script called "proxyless-clone" (name does not really matter) that does these steps:

#!/bin.sh
http_proxy=$(git config http.proxy)
https_proxy=$(git config https.proxy)
git config --global --unset http.proxy
git config --global --unset https.proxy
git clone "$1"
git config --global http.proxy "$http_proxy"
git config --global https.proxy "$https_proxy"

This script still has a few "problems", namely that 2 instances cannot run at the same time without messing up the git config files (see it as a threading bug), but for something and 1-shot only thing like cloning, I don't think that will be a problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM