如何确定最初克隆本地 Git 存储库的 URL?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4089430/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I determine the URL that a local Git repository was originally cloned from?
提问by Tim
I pulled a project from GitHub a few days ago. I've since discovered that there are several forks on GitHub, and I neglected to note which one I took originally. How can I determine which of those forks I pulled?
前几天从 GitHub 拉了一个项目。后来我发现 GitHub 上有好几个分叉,我忽略了我最初拿的是哪一个。我如何确定我拉的是哪个叉子?
回答by JaredPar
If you want only the remote URL, or if your are not connected to a network that can reach the remote repo:
如果您只需要远程 URL,或者您没有连接到可以访问远程存储库的网络:
git config --get remote.origin.url
If you require full output and you areon a network that can reach the remote repo where the origin resides :
如果您需要完整的输出,你是哪里的来源所在,可以达到远程回购在网络上:
git remote show origin
When using git clone
(from GitHub, or any source repository for that matter) the default name for the source of the clone is "origin". Using git remote show
will display the information about this remote name. The first few lines should show:
使用git clone
(来自 GitHub 或任何与此相关的源存储库)时,克隆源的默认名称为“origin”。使用git remote show
将显示有关此远程名称的信息。前几行应显示:
C:\Users\jaredpar\VsVim> git remote show origin
* remote origin
Fetch URL: [email protected]:jaredpar/VsVim.git
Push URL: [email protected]:jaredpar/VsVim.git
HEAD branch: master
Remote branches:
If you want to use the value in the script, you would use the first command listed in this answer.
如果要使用脚本中的值,可以使用此答案中列出的第一个命令。
回答by Cascabel
Should you want this for scripting purposes, you can get only the URL with
如果您希望将其用于脚本目的,则只能获取带有以下内容的 URL
git config --get remote.origin.url
回答by Montaro
You can try:
你可以试试:
git remote -v
It will print all your remotes' fetch/push URLs.
它将打印您所有遥控器的获取/推送 URL。
回答by Carl Suster
To get the answer:
要得到答案:
git ls-remote --get-url [REMOTE]
This is better than reading the configuration; refer to the man page for git-ls-remote
:
这比阅读配置要好;请参阅手册页了解git-ls-remote
:
--get-url
Expand the URL of the given remote repository taking into account any
"url.<base>.insteadOf"
config setting (Seegit-config(1)
) and exit without talking to the remote.
--get-url
扩展给定远程存储库的 URL,考虑任何
"url.<base>.insteadOf"
配置设置(请参阅 参考资料git-config(1)
)并退出而不与远程通信。
As pointed out by @Jefromi, this option was added in v1.7.5and not documented until v1.7.12.2(2012-09).
正如@Jefromi 所指出的,这个选项是在v1.7.5中添加的,直到v1.7.12.2(2012-09)才被记录下来。
回答by VonC
With Git 2.7 (release January 5th, 2015), you have a more coherent solution using git remote
:
使用 Git 2.7(2015 年 1 月 5 日发布),您可以使用git remote
以下方法获得更一致的解决方案:
git remote get-url origin
(nice pendant of git remote set-url origin <newurl>
)
(漂亮的吊坠git remote set-url origin <newurl>
)
See commit 96f78d3(16 Sep 2015) by Ben Boeckel (mathstuf
).
(Merged by Junio C Hamano -- gitster
--in commit e437cbd, 05 Oct 2015):
请参阅Ben Boeckel( )提交的 96f78d3(2015 年 9 月 16 日)。(由Junio C Hamano合并-- --在提交 e437cbd,2015 年 10 月 5 日):mathstuf
gitster
remote: add get-url subcommand
Expanding
insteadOf
is a part ofls-remote --url
and there is no way to expandpushInsteadOf
as well.
Add aget-url
subcommand to be able to query both as well as a way to get all configured URLs.
远程:添加 get-url 子命令
扩展
insteadOf
是其中的一部分,ls-remote --url
也无法扩展pushInsteadOf
。
添加一个get-url
子命令以能够查询两者以及获取所有配置的 URL 的方法。
get-url:
Retrieves the URLs for a remote.
Configurations forinsteadOf
andpushInsteadOf
are expanded here.
By default, only the first URL is listed.
- With '
--push
', push URLs are queried rather than fetch URLs.- With '
--all
', all URLs for the remote will be listed.
检索远程的 URL。
对于配置insteadOf
和pushInsteadOf
正在这里展开。
默认情况下,只列出第一个 URL。
- 使用“
--push
”,查询推送 URL 而不是获取 URL。- 使用“
--all
”,将列出远程的所有 URL。
Before git 2.7, you had:
在 git 2.7 之前,你有:
git config --get remote.[REMOTE].url
git ls-remote --get-url [REMOTE]
git remote show [REMOTE]
回答by nonopolarity
To summarize, there are at least four ways:
总结起来,至少有四种方式:
(The following was tried for the official Linux repository)
(以下针对官方Linux存储库进行了尝试)
Least information:
最少信息:
$ git config --get remote.origin.url
https://github.com/torvalds/linux.git
and
和
$ git ls-remote --get-url
https://github.com/torvalds/linux.git
More information:
更多信息:
$ git remote -v
origin https://github.com/torvalds/linux.git (fetch)
origin https://github.com/torvalds/linux.git (push)
Even more information:
更多信息:
$ git remote show origin
* remote origin
Fetch URL: https://github.com/torvalds/linux.git
Push URL: https://github.com/torvalds/linux.git
HEAD branch: master
Remote branch:
master tracked
Local branch configured for 'git pull':
master merges with remote master
Local ref configured for 'git push':
master pushes to master (up to date)
回答by meder omuraliev
I think you can find it under .git/config
and remote["origin"]
if you didn't manipulate that.
我想你可以在下面找到它.git/config
,remote["origin"]
如果你没有操纵它。
回答by Casey
Short answer:
简短的回答:
$ git remote show -n origin
or, an alternative for pure quick scripts:
或者,纯快速脚本的替代方案:
$ git config --get remote.origin.url
Some info:
一些信息:
$ git remote -v
will print all remotes (not what you want). You want origin right?$ git remote show origin
much better, shows onlyorigin
but takes too long (tested on git version 1.8.1.msysgit.1).
$ git remote -v
将打印所有遥控器(不是你想要的)。你要起源对吗?$ git remote show origin
好多了,只显示origin
但需要太长时间(在 git 版本 1.8.1.msysgit.1 上测试)。
I ended up with: $ git remote show -n origin
, which seems to be fastest. With -n
it will not fetch remote heads (AKA branches). You don't need that type of info, right?
我结束了:$ git remote show -n origin
,这似乎是最快的。使用-n
它不会获取远程头(AKA 分支)。你不需要那种信息,对吧?
http://www.kernel.org/pub//software/scm/git/docs/git-remote.html
http://www.kernel.org/pub//software/scm/git/docs/git-remote.html
You can apply | grep -i fetch
to all three versions to show only the fetch URL.
您可以申请| grep -i fetch
所有三个版本以仅显示提取 URL。
If you require pure speed, then use:
如果您需要纯速度,请使用:
$ git config --get remote.origin.url
Thanks to @Jefromifor pointing that out.
感谢@Jefromi指出这一点。
回答by Code Knox
For me, this is the easier way (less typing):
对我来说,这是更简单的方法(少打字):
$ git remote -v
origin https://github.com/torvalds/linux.git (fetch)
origin https://github.com/torvalds/linux.git (push)
actually, I've that into an alias
called s
that does:
实际上,我已经把它变成了一个alias
调用s
:
git remote -v
git status
You can add to your profile with:
alias s='git remote -v && git status'
您可以添加到您的个人资料:
alias s='git remote -v && git status'
回答by What Would Be Cool
I can never remember all the parameters to Git commands, so I just put an alias in the ~/.gitconfig
file that makes more sense to me, so I can remember it, and it results in less typing:
我永远无法记住 Git 命令的所有参数,所以我只是在~/.gitconfig
文件中放了一个对我更有意义的别名,这样我就可以记住它,这样可以减少输入:
[alias]
url = ls-remote --get-url
After reloading the terminal, you can then just type:
重新加载终端后,您只需键入:
> git url
Here are a few more of my frequently used ones:
以下是我经常使用的一些:
[alias]
cd = checkout
ls = branch
lsr = branch --remote
lst = describe --tags
I also highly recommend git-extraswhich has a git info
commandwhich provides much more detailed information on the remote and local branches.
我还强烈推荐git-extras,它有一个git info
命令,可以提供有关远程和本地分支的更多详细信息。