我在GitHub上拖了一個有幾個福克的項目,但忘記了它是哪個福克。


当前回答

你用SSH克隆来克隆你的存储库。

git config --get remote.origin.url
git@gitlab.com:company/product/production.git

但是,您想要在浏览器中打开或分享一个 HTTP URL:

git config --get remote.origin.url | sed -e 's/:/\//g'| sed -e 's/ssh\/\/\///g'| sed -e 's/git@/https:\/\//g'

https://gitlab.com/company/product/production.git

GitHub 或 GitLab 不重要。

其他回答

git config --list

此命令将提供与您的存储库相关的所有信息。

只需获取远程URL:

git config --get remote.origin.url

如果您需要完整的输出,并且您正在网络上,可以到达原产地的远程雷波:

git remote show origin

当使用 git clone (从 GitHub,或任何源存储器为该材料) 的默认名称为 clone 的来源是“起源”。使用 git 远程显示将显示有关这个远程名称的信息。

C:\Users\jaredpar\VsVim> git remote show origin
* remote origin
  Fetch URL: git@github.com:jaredpar/VsVim.git
  Push  URL: git@github.com:jaredpar/VsVim.git
  HEAD branch: master
  Remote branches:

如果你想在脚本中使用值,你会使用这个答案中列出的第一个命令。

#!/bin/bash

git-remote-url() {
 local rmt=$1; shift || { printf "Usage: git-remote-url [REMOTE]\n" >&2; return 1; }
 local url

 if ! git config --get remote.${rmt}.url &>/dev/null; then
  printf "%s\n" "Error: not a valid remote name" && return 1
  # Verify remote using 'git remote -v' command
 fi

 url=`git config --get remote.${rmt}.url`

 # Parse remote if local clone used SSH checkout
 [[ "$url" == git@* ]] \
 && { url="https://github.com/${url##*:}" >&2; }; \
 { url="${url%%.git}" >&2; };

 printf "%s\n" "$url"
}

使用:

# Either launch a new terminal and copy `git-remote-url` into the current shell process, 
# or create a shell script and add it to the PATH to enable command invocation with bash.

# Create a local clone of your repo with SSH, or HTTPS
git clone git@github.com:your-username/your-repository.git
cd your-repository

git-remote-url origin

出口:

https://github.com/your-username/your-repository

我更喜欢这个,因为更容易记住:

git config -l

它将列出所有有用的信息,如:

user.name=Your Name
user.email=your.name@notexisting.com
core.autocrlf=input
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
remote.origin.url=https://github.com/mapstruct/mapstruct-examples
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master

Git URL 将位于 Git 配置文件中,值相当于关键 URL。

对于 Mac 和 Linux,请使用下面的命令:

cd project_dir
cat .git/config | grep url | awk '{print $3}'

在 Windows 中,在任何文本编辑器中打开下面的文件,并找到关键URL的值。

project_dir/.git/config

注意: 即使您离线或远程 Git 服务器已被删除,这也将工作。