简体   繁体   English

使用 git 推送或拉取时如何抑制存储库 url?

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

I have a repository that has a remote to azure-devops.我有一个存储库,它有一个到 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.您可以向远程 url 添加令牌(以https://user:pat@dev.azure.com/..的形式),我这样做是因为每次复制粘贴 pat 很烦人。

When pushing or pulling, the full url is displayed.推或拉时,会显示完整的 url。

$ 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?如何抑制“To https ...”行?

Edit : This is not a duplicate, because that answer changes authentication protocol to ssh keys.编辑:这不是重复的,因为该答案将身份验证协议更改为 ssh 密钥。 Because I have to use a proxy (see second paragraph) I can't use ssh keys.因为我必须使用代理(参见第二段),所以我不能使用 ssh 密钥。

@ochi pointed to a comment on another, similar question. @ochi 指出了对另一个类似问题的评论。 The following comment held my answer. 以下评论保留了我的答案。

Using .netrc to hold my authentication information works as desired.使用.netrc来保存我的身份验证信息可以正常工作。 Make sure to chmod 0600 ~/.netrc or it won't work.确保chmod 0600 ~/.netrc否则它不会工作。

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. .netrc文件由其他应用程序使用,并且这些信息可供他们使用。 This works in my situation, you should evaluate yours and decide if this is what you want.这在我的情况下有效,您应该评估您的情况并决定这是否是您想要的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何配置远程Git存储库以进行推送,不进行提取或拉取? - How can a remote Git repository be configured for pushing to, no fetching or pulling? 如何合并更改而不从GIT存储库中提取? - How do I merge changes without pulling from a GIT repository? 在向/从 github 存储库推送、拉取或合并代码时,我是否需要停止我的本地主机服务器? - Do i need to stop my localhost server when pushing, pulling or merging code to/from github repository? 使用git推送或拉取时如何保留用户上传的内容 - How to preserve user uploaded content when pushing or pulling with git 从 git 输出推送到远程服务器时,我可以隐藏远程存储库 URL 吗? - Can I hide remote repository URL when pushing to remote server from git output? 在 git 中获取/拉取时如何忽略其他目录? - How do I ignore other directories when fetching/pulling in git? GIT:拉动时忽略文件但推动时不忽略 - GIT: Ignore file when pulling but not when pushing 使用git推和拉时出现SSL错误 - SSL errors when pushing and pulling with git 在团队中工作时Git拉动和推动 - Git pulling and pushing when working in a team 如何使用git子存储库推送到私有远程但又从其原始来源拉出 - How to use a git sub repository pushing to a private remote but pulling also from its original origin
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM