Git User and Proxy Settings - chaitanyavangalapudi/devops-scripts GitHub Wiki
Git User Settings Configuration
Step #1 Configure user and email
Run below commands to set the user settings
$ git config --global user.name "chaitanya.vangalapudi"
$ git config --global user.email [email protected]
Step #2 Configure default user for each Git Repository host
You can set default username for all repositories under a host by putting the following configuration in your Git configuration file. You can repeat this for as many repository hosts as you want.
[credential "https://git.mycompany.com"]
username = vkchaitanya
[credential "https://github.com"]
username = chaitanya.vangalapudi
With this setup, you don't need to type your username every time when you do git operations.
Step #3 Configure password to be cached
If you want to avoid typing password also, you can store your credentials using the following command
$ git config credential.helper store
$ git push http://git.example.com/repo.git
Username: <type your username>
Password: <type your password>
Use should also specify caching expire for security purposes
git config --global credential.helper "cache --timeout 7200"
After enabling credential caching, it will be cached for 7200 seconds (2 hours).
WARNING: If you use credential.helper store from the answer, your password is going to be stored completely unencrypted ("as is") at ~/.git-credentials.
Git Proxy Server Settings Configuration
Method #1
Pass proxy details to git config via command line. You can do this in Linux on shell prompt and using GitBash on windows.
Step #1 Check the location of .gitconfig file
git config --list --global --show-origin
Step #2 Set the http and https proxy
git config --global http.proxy http://proxyuser:[email protected]:8080
git config --global https.proxy http://proxyuser:[email protected]:8080
- change proxyuser to your proxy user
- change proxypwd to your proxy password
- change proxy.server.com to the URL of your proxy server
- change 8080 to the proxy port configured on your proxy server
You can unset this proxy to bypass proxy at any point of time by executing :
git config --global --unset http.proxy
Finally, to check the currently set proxy:
git config --global --get http.proxy
Note: In case your password contains any special characters like @, you can replace it by using corresponding ascii character. Suppose your password is passwd@123 , you can use passwd%40123
@ - %40 - passwd%40123
$ - %24 - passwd%24123
- Spaces in the proxy passwordd should be encoded as "+". eg "My Password" should be entered as "My+Password".
git config --global http.proxy http://proxyuser:passwd%[email protected]:8080
Method #2
You can also set http proxy by editing the .gitconfig file typically found in your home directory ~/.gitconfig.
Paste below content to .gitconfig:
[http]
proxy = http://proxyuser:[email protected]:8080
sslverify = false
[https]
proxy = http://proxyuser:[email protected]:8080
sslverify = false
[user]
name = myGitUser
email = [email protected]
[url "https://"]
insteadOf = git://
References:
- https://www.w3schools.com/tags/ref_urlencode.asp
- https://confluence.atlassian.com/bitbucketserver/permanently-authenticating-with-git-repositories-776639846.html
- https://stackoverflow.com/questions/783811/getting-git-to-work-with-a-proxy-server
- https://git-scm.com/book/en/v2/Getting-Started-First-Time-Git-Setup
- https://git-scm.com/docs/git-config
- https://stackoverflow.com/questions/6565357/git-push-requires-username-and-password
- https://stackoverflow.com/questions/11403407/git-asks-for-username-every-time-i-push
- https://git-scm.com/book/en/v2/Git-Tools-Credential-Storage