上下文:我有origin
克隆存储库后使用默认 url 进行远程操作。由于 Bitbucket 的一些更新,建议我们的团队通过为团队处理的所有项目创建另一个具有一个应用程序密码的帐户来集中存储库。
首先,我决定使用以下方法添加另一个 Remote :
git remote add norigin <new url>
但是每次都推两个 Remote 会很麻烦。 我对一键命令解决方案的搜索给我带来了 here .
基本上,您可以编辑/添加另一个网址到现有的 Remote ,因此我输入:
git remote set-url --add --push origin <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e98e809da98b809d8b9c8a828c9dc78a8684" rel="noreferrer noopener nofollow">[email protected]</a>:username/repo2
测试现在是否 git push origin <some branch>
命令将推送到两个远程 URL。 git log
然后会显示 norigin
会比 origin
落后一个提交,但我认为这是因为它仍然被视为另一个单独的 Remote ,然后检查了每个单独的存储库,它确实推送到两个存储库,因此我删除了 norigin
远程。
一切都很好,但是当我输入git remote -v
时它只会显示:
origin <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="395e504d795b504d5b4c5a525c4d175a5654" rel="noreferrer noopener nofollow">[email protected]</a>:username/repo (fetch)
origin <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f4939d80b4969d809681979f9180da979b99" rel="noreferrer noopener nofollow">[email protected]</a>:username/repo2 (push)
当预期输出应该是:
origin <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c4a3adb084a6adb0a6b1a7afa1b0eaa7aba9" rel="noreferrer noopener nofollow">[email protected]</a>:username/repo (fetch)
origin <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="82e5ebf6c2e0ebf6e0f7e1e9e7f6ace1edef" rel="noreferrer noopener nofollow">[email protected]</a>:username/repo (push)
origin <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8ee9e7faceece7faecfbede5ebfaa0ede1e3" rel="noreferrer noopener nofollow">[email protected]</a>:username/repo2 (push)
问题:如标题所述和显示的预期输出,如何显示在特定 Remote 上添加的所有网址?
我尝试过的:
git remote -v show origin
git remote get-url --push origin
git remote get-url --all origin
但它们都返回一个 url,并且它要么是旧的 url,要么是新的 url。
最佳答案
这可能取决于所使用的 Git 版本。
我刚刚使用 Git 2.35.1 测试了您的命令,git remote -v
按预期工作:
origin <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="56313f2216343f223423353d33227835393b" rel="noreferrer noopener nofollow">[email protected]</a>:username/repo1 (fetch)
origin <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a7c0ced3e7c5ced3c5d2c4ccc2d389c4c8ca" rel="noreferrer noopener nofollow">[email protected]</a>:username/repo1 (push)
origin <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d1b6b8a591b3b8a5b3a4b2bab4a5ffb2bebc" rel="noreferrer noopener nofollow">[email protected]</a>:username/repo2 (push)
检查.git/config是否包含
[remote "origin"]
url = <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0a6d637e4a68637e687f69616f7e24696567" rel="noreferrer noopener nofollow">[email protected]</a>:username/repo1
fetch = +refs/heads/*:refs/remotes/origin/*
pushurl = <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="85e2ecf1c5e7ecf1e7f0e6eee0f1abe6eae8" rel="noreferrer noopener nofollow">[email protected]</a>:username/repo1
pushurl = <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="20474954604249544255434b45540e434f4d" rel="noreferrer noopener nofollow">[email protected]</a>:username/repo2
关于Git:如何显示远程添加的所有网址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71121615/