Jak Mogę określić adres URL, z którego sklonowano lokalne repozytorium Git?
Kilka dni temu wyciągnąłem projekt z Githuba. Od tego czasu odkryłem, że na Githubie jest kilka widelców i zaniedbałem zauważyć, który z nich wziąłem pierwotnie. Jak Mogę określić, który z tych widelców pociągnąłem?
19 answers
Jeśli chcesz tylko zdalny adres URL, lub integralność odniesienia została złamana:
git config --get remote.origin.url
Jeśli wymagane jest pełne wyjście lub integralność odniesienia jest nienaruszona:
git remote show origin
Podczas używania git clone
(z GitHub lub dowolnego repozytorium źródłowego) domyślną nazwą dla źródła klonu jest "origin". Użycie git remote show
wyświetli informacje o tej zdalnej nazwie. Pierwsze wiersze powinny pokazywać:
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:
Jeśli chcesz użyć wartości w skrypcie, użyj pierwszego polecenie wymienione w tej odpowiedzi.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-04-16 13:24:57
Jeśli chcesz to dla celów skryptowych, możesz uzyskać tylko adres URL z
git config --get remote.origin.url
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-02-17 19:34:10
Możesz spróbować:
git remote -v
Wyświetli adresy URL wszystkich pilotów.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-02-24 04:19:43
Aby uzyskać odpowiedź:
git ls-remote --get-url [REMOTE]
Jest to lepsze niż czytanie konfiguracji; zobacz stronę podręcznika dla git-ls-remote
:
--get-url
Rozwiń adres URL danego zdalnego repozytorium z uwzględnieniem dowolne ustawienie konfiguracyjne
"url.<base>.insteadOf"
(Patrzgit-config(1)
) oraz wyjście bez rozmowy z pilotem.
Jak zauważył @Jefromi, ta opcja została dodana w v1.7.5 i nie udokumentowana do v1.7.12.2 (2012-09).
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-07-25 20:12:46
Z Git 2.7 (wydanie 5 stycznia 2015), masz bardziej spójne rozwiązanie używając git remote
:
git remote get-url origin
(ładny wisiorek z git remote set-url origin <newurl>
)
Zobacz commit 96f78d3 (16 Sep 2015) by Ben Boeckel (mathstuf
).
(dodany przez Junio C Hamano -- gitster
-- in commit e437cbd, 05 Oct 2015):
Remote: dodaj subkomand get-url
Rozszerzenie
insteadOf
jest częściąls-remote --url
i nie ma możliwości aby rozwinąćpushInsteadOf
jako cóż.
Dodaj subkomendęget-url
, aby móc odpytywać zarówno jak i uzyskać wszystkie skonfigurowane adresy URL.
get-url:
Pobiera adresy URL dla pilota.
Konfiguracje dlainsteadOf
ipushInsteadOf
są tutaj rozszerzone.
Domyślnie wyświetlany jest tylko pierwszy adres URL.
- za pomocą '
--push
', wypychane adresy URL są odpytywane zamiast pobierać adresy URL.- Z '
--all
' zostaną wyświetlone wszystkie adresy URL dla pilota.
Przed git 2.7, ty miał:
git config --get remote.[REMOTE].url
git ls-remote --get-url [REMOTE]
git remote show [REMOTE]
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-01-05 08:03:18
Podsumowując, istnieją co najmniej cztery sposoby:
[[4]}(poniższe zostało wypróbowane dla oficjalnego repozytorium Linuksa)Najmniej Informacji:
$ git config --get remote.origin.url
https://github.com/torvalds/linux.git
I
$ git ls-remote --get-url
https://github.com/torvalds/linux.git
Więcej informacji:
$ git remote -v
origin https://github.com/torvalds/linux.git (fetch)
origin https://github.com/torvalds/linux.git (push)
Jeszcze więcej informacji:
$ 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)
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-11-01 10:28:17
Krótka odpowiedź:
$ git remote show -n origin
Lub alternatywa dla czystych szybkich skryptów:
$ git config --get remote.origin.url
Niektóre informacje:
-
$ git remote -v
wydrukuje wszystkie piloty (nie to, co chcesz). Chcesz pochodzenia, prawda? -
$ git remote show origin
znacznie lepiej, pokazuje tylkoorigin
ale trwa zbyt długo (testowane na git w wersji 1.8.1.msysgit.1).
Skończyłem z: $ git remote show -n origin
, który wydaje się być najszybszy. Z -n
nie pobierze zdalnych głowic (aka branches). Nie potrzebujesz tego typu informacji, prawda?
Http://www.kernel.org/pub//software/scm/git/docs/git-remote.html
Możesz zastosować | grep -i fetch
do wszystkich trzech wersji, aby pokazać tylko adres URL pobierania.
Jeśli potrzebujesz czystej prędkości, użyj:
$ git config --get remote.origin.url
Dzięki @Jefromi za wskazanie tego.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-05-23 12:18:26
Myślę, że możesz go znaleźć pod .git/config
i remote["origin"]
jeśli tego nie zmanipulowałeś.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-11-03 16:50:48
Zdalny upstream nie może być nazywany "origin" , więc oto odmiana:
remote=$(git config --get branch.master.remote)
url=$(git config --get remote.$remote.url)
basename=$(basename "$url" .git)
echo $basename
Lub:
basename $(git config --get remote.$(git config --get branch.master.remote).url) .git
Dla bardziej użytecznych zmiennych jest:
$ git config -l
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-07-25 20:05:54
Aby uzyskać adres IP / nazwę hosta origin
Dla ssh://
repozytoriów:
git ls-remote --get-url origin | cut -f 2 -d @ | cut -f 1 -d "/"
Dla git://
repozytoriów:
git ls-remote --get-url origin | cut -f 2 -d @ | cut -f 1 -d ":"
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-11-01 10:29:03
Adres URL Gita znajdzie się w pliku konfiguracyjnym Gita. Wartość odpowiada kluczowi url
:
cd project_dir
cat .git/config | grep url | awk '{print $3}'
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-07-25 20:16:51
Aby uzupełnić pozostałe odpowiedzi: jeśli pilot został z jakiegoś powodu zmieniony, a więc nie odzwierciedla oryginalnego pochodzenia, pierwszy wpis w reflogu (tzn. ostatni wpis wyświetlony przez komendęgit reflog
) powinien wskazywać, skąd repo zostało pierwotnie sklonowane.
Np.
$ git reflog | tail -n 1
f34be46 HEAD@{0}: clone: from https://github.com/git/git
$
(Pamiętaj, że reflog może zostać wyczyszczony, więc to nie jest gwarantowane.)
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-11-16 12:58:41
Nigdy nie pamiętam wszystkich parametrów komend Gita, więc po prostu umieściłem alias w pliku ~/.gitconfig
, który ma dla mnie większy sens, więc mogę go zapamiętać, a to powoduje mniej wpisywania:
[alias]
url = ls-remote --get-url
Po przeładowaniu terminala, możesz po prostu wpisać:
> git url
Oto jeszcze kilka moich często używanych:
[alias]
cd = checkout
ls = branch
lsr = branch --remote
lst = describe --tags
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-07-25 20:18:18
Wypisuje dowolnie nazwane adresy URL zdalnego pobierania:
git remote -v | grep fetch | awk '{print $2}'
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-09-01 14:34:45
Z git remote show origin
Musisz być w katalogu projects. Ale jeśli chcesz określić adresy URL z dowolnego miejsca
można użyć:
cat <path2project>/.git/config | grep url
Jeśli potrzebujesz tego polecenia często, możesz zdefiniować alias w swoim .bashrc
lub .bash_profile
w systemie MacOS.
alias giturl='cat ./.git/config | grep url'
Więc wystarczy wywołać giturl
w głównym folderze Git, aby po prostu uzyskać jego adres URL.
Jeśli rozszerzysz Ten alias w ten sposób
alias giturl='cat .git/config | grep -i url | cut -d'=' -f 2'
Otrzymujesz tylko zwykły adres URL bez poprzedzającego
"url="
W
Masz więcej możliwości w jego użyciu:
Przykład
Na Macu można wywołać open $(giturl)
, aby otworzyć adres URL w standardowej przeglądarce.
Lub chrome $(giturl)
, aby otworzyć go w przeglądarce Chrome na Linuksie.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-07-25 08:12:52
Prostym sposobem jest otwarcie pliku .git/config
:
cat .git/config
Do edycji:
vim .git/config
lub
nano .git/config
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-07-25 20:14:21
W zasadzie używam:
git remote get-url origin
Działa dla konsoli poleceń Git Bash lub konsoli poleceń CMD w systemie Windows. To powiedziawszy, działa z wersją 2.x Git.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-07-25 20:17:21
Jeśli nie znasz nazwy zdalnego źródła dla gałęzi, możesz sprawdzić ją najpierw, sprawdzając nazwę gałęzi, na której została zbudowana bieżąca gałąź. Użyj git rev-parse
w ten sposób:
git rev-parse --symbolic-full-name --abbrev-ref @{upstream}
To pokazuje, że gałąź upstream, która była źródłem bieżącej gałęzi. Można to przetworzyć, aby uzyskać zdalną nazwę w ten sposób:
git rev-parse --symbolic-full-name --abbrev-ref @{upstream} | cut -d / -f 1
Teraz weź to i podłącz do git ls-remote
, a otrzymasz adres URL pilota, który jest źródłem prądu "branch": {]}
git ls-remote --get-url \
$(git rev-parse --symbolic-full-name --abbrev-ref @{upstream} | cut -d / -f 1)
Teraz należy zauważyć, że niekoniecznie jest to to samo, co zdalne repozytorium źródłowe, z którego zostało sklonowane. W wielu przypadkach jednak to wystarczy.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-08-09 00:38:04
#!/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"
}
Użycie:
# 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 [email protected]:your-username/your-repository.git
cd your-repository
git-remote-url origin
Wyjście:
https://github.com/your-username/your-repository
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-02-01 21:56:42