简体   繁体   中英

How do I suppress the repository url when pushing or pulling with git?

I have a repository that has a remote to azure-devops.

I have to go through a proxy if that matters, but that's setup and working correctly. I don't think this will be an issue for this question.

You can add a token to the remote url (in the form of https://user:pat@dev.azure.com/.. .), which I do because copy-n-pasting the pat every single time is annoying.

When pushing or pulling, the full url is displayed.

$ git push azure dev
Counting objects: 3, done.
Delta compression using up to 12 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 279 bytes | 0 bytes/s, done.
Total 2 (delta 1), reused 0 (delta 0)
remote: Analyzing objects... (2/2) (163 ms)
remote: Storing packfile... done (177 ms)
remote: Storing index... done (31 ms)
To https://user:mypat@dev.azure.com/user/path/to/repo <<<---
   b20e4fd..b1772a1  dev -> dev

How can I suppress the 'To https...' line?

Edit : This is not a duplicate, because that answer changes authentication protocol to ssh keys. Because I have to use a proxy (see second paragraph) I can't use ssh keys.

@ochi pointed to a comment on another, similar question. The following comment held my answer.

Using .netrc to hold my authentication information works as desired. Make sure to chmod 0600 ~/.netrc or it won't work.

machine dev.azure.com
login user
password personalaccesstoken

This is the output I'm getting now.

$ git push azure test
Counting objects: 3, done.
Delta compression using up to 12 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 289 bytes | 0 bytes/s, done.
Total 2 (delta 1), reused 0 (delta 0)
remote: Analyzing objects... (2/2) (126 ms)
remote: Storing packfile... done (244 ms)
remote: Storing index... done (95 ms)
To https://dev.azure.com/user/path/to/repo <<<---
   24a77ad..5ee5fcb  HEAD -> test

Updated

As pointed out in the comments, this is not a perfect solution. The .netrc file is used by other applications and this information will be available to them. This works in my situation, you should evaluate yours and decide if this is what you want.

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