git의 성가심은 일부 업스트림 저장소 (예 : Github 포크)에서 분기 된 저장소의 모든 복제본에 git remote add upstream URL
을 사용해야합니다. 이상적으로는 모든 복제본이 자동으로 설정되도록 포크 된 저장소 자체에 업스트림 위치를 저장할 수 있어야합니다. 거기에 자식을 사용하여 이것을 달성하는 방법이 있습니까?git repo에 업스트림 위치를 영구적으로 추가하는 방법은 무엇입니까?
답변
다른 답변 상태로, 자식은 현재 repos를 함께 연결하기위한 기본 제공 기능이 없습니다.
따라서 나는 BitBucket 및 GitHub에 대한 업스트림 저장소를 구문 분석하고 upstream
이라는 원격 저장소로 추가하기 위해 BeatifulSoup 4를 사용하는 clone
이라는 작은 Python 스크립트를 작성했습니다. 이것은 git와 Mercurial 모두에서 작동합니다. hosted on GitHub이지만 완료하려면이 답변에 전체 스크립트를 포함합니다.
#! /usr/bin/env python3
description='''
A wrapper for repo cloning commands for various DVCS.
Automatically adds the upstream URL when cloning a forked repo from
popular DVCS web hosts.
Currently supports:
(DVCS: git, Mercurial)
(hosts: GitHub, Bitbucket)
'''
# Created by Jesse Johnson a.k.a. holocronweaver (2014-10-08).
import argparse
import re
import subprocess
import urllib.request
from bs4 import BeautifulSoup
def find(regex, string, errorMessage):
'''Return value at regex, or else print error message and exit program.'''
m = re.search(regex, string)
if (m):
return m.group(1)
else:
print('Error:', errorMessage)
exit()
parser = argparse.ArgumentParser(description=description)
parser.add_argument('origin', metavar='O', type=str,
help='the SSH URL of origin repo, optionally'
'followed by its destination folder')
args = parser.parse_args()
# Parse destination.
splitArgs = re.split('\s+', args.origin)
if len(splitArgs) > 1:
origin = splitArgs[0]
destination = splitArgs[1]
else:
origin = args.origin
destination = find('@.*\.\w+[:|/].*/(.*)[.git]?$', origin,
'Error: Could not parse destination folder from origin URL.')
destination = re.sub('\.git', '', destination)
print('destination folder:', destination)
# Unfortunately HTTPS URLs do not contain enough info to clarify which
# DVCS is being used, so SSH is easiest to support.
vcs = find('^[ssh://]?(.*)@', origin,
'URL does not contain SSH user (e.g., [email protected] or [email protected]).')
print('version control system:', vcs)
domain = find('@(.*\.\w+)[:|/]', origin,
'Error: Could not parse domain from origin URL.')
print('domain:', domain)
path = find('@.*\.\w+([:|/].*)[.git]?$', origin,
'Error: Could not parse repo path from origin URL.')
path = re.sub(':', '/', path)
print('repo path:', path)
homepage = 'https://' + domain + path
print(homepage)
data = urllib.request.urlopen(homepage).read()
soup = BeautifulSoup(data)
# Version control system specifics.
if ('[email protected]' in origin):
ext = '.git'
clone = 'git clone %s %s'
setUpstream = 'git remote add upstream %s'
elif ('[email protected]' in origin):
ext = ''
clone = 'hg clone %s %s'
setUpstream = 'echo "upstream = %s \n" >> .hg/hgrc'
else:
print('Error: Version control system not supported.')
exit()
upstream = None
if ('github.com' in origin):
element = soup.find('span', class_='fork-flag')
if element:
upstreamBase = element.span.a['href']
upstream = 'https://github.com' + upstreamBase + ext
elif ('bitbucket.org' in origin):
element = soup.find('a', class_='fork-of')
if element:
upstreamBase = element['href']
upstream = 'https://bitbucket.org' + upstreamBase + ext
else:
print('Warning: Web host not supported.')
print('Warning: Continuing to clone without adding upstream repo.')
print(upstream)
subprocess.Popen(clone % (origin, destination), shell=True).wait()
if upstream:
subprocess.Popen(setUpstream % upstream, cwd=destination, shell=True).wait()
기본적으로 git clone
은 원격 "출발지"를 호출합니다. 당신이 원하는 경우 다른 것을 사용
git clone -o upstream <path_to_repo>
--origin <name>
-o <name>
Instead of using the remote name origin to keep track of the upstream repository, use <name>.
편집라는 : 원격 원격을 추적 할 필요의 사건을 위해 ... 내가 할 수있는 좋은 방법을 발견 한 적이 이. git clone
주위에 래퍼를 작성할 수 있지만 각 저장소마다 하드 코딩해야합니다.
Git 자체와 관련하여 원래의 저장소 (즉, 사용자가 분기 한 저장소)와 포크의 복제본 간에는 아무런 관련이 없습니다. 이전 URL에 대한 정보는 후자에 포함되어 있지 않습니다. 따라서 어떤 방법으로 복제하려면 복제 후 복제본의 리모컨으로 원래 repo를 추가해야합니다 ().
, 당신은 당신이에서 갈래의 각 프로젝트에 대한 별명 정의 할 수 있습니다 것들을 작은 비트를 자동화하고 URL을 매번 입력 할 필요가 없도록하려면 포크를 복제 한 후
git config alias.remaddfoo "remote add upstream <URL-of-original-project-foo>"
을, 당신은 내부 cd
할 것 새로운 복제본을 만들고 해당 별칭을 호출하는 것을 잊지 마십시오. 더
촬영 자동화 한 단계는 복제 내부 git clone
것 자동으로 cd
주위에 래퍼의 어떤 종류를 작성 포함하고 git remote add...
을 실행하지만, git clone
의 인수를 구문 분석 올바르게 조금 너무 복잡 할 수있다.
- 1. git repo에 vim-plugins를 추가하는 방법은 무엇입니까?
- 2. 업스트림 브랜치를 다운로드하는 방법은 무엇입니까?
- 3. git rebase 업스트림/마스터 대 git 풀 -베이스 업스트림 마스터
- 4. Git 병합 업스트림 브랜치
- 5. SSH를 사용하여 git repo에 다이얼
- 6. PYTHONPATH에 디렉토리를 영구적으로 추가하는 방법은 무엇입니까?
- 7. git github repo에 커밋
- 8. git 저장소에 tar 파일을 추가하는 방법은 무엇입니까?
- 9. git 저장소에 과거를 추가하는 방법은 무엇입니까?
- 10. 다른 repo에서 현재 repo에 파일을 추가하는 방법
- 11. git repo를 추가하는 방법은 무엇입니까?
- 12. git 브랜치의 업스트림 레퍼런스를 읽기 전용으로 만드는 방법은 무엇입니까?
- 13. git 브랜치는 업스트림 브랜치를 나열합니다.
- 14. Git Gui와 함께 리모컨을 추가하는 방법은 무엇입니까?
- 15. 초기 커밋을 추가하고 기존 git repo에 파일을 보내는 방법은 무엇입니까?
- 16. git-repo 하나의 Google repo에 모든 지점을 나열하는 방법은 무엇입니까?
- 17. 로컬 커밋, 업스트림 커밋 및 배포를위한 Git 워크 플로
- 18. ssh 공개 키를 특정 git repo에 추가하는 방법
- 19. git repo에 svn 커밋을 추가합니다.
- 20. GIt repo에 SVN 패치 적용
- 21. 원격 git repo에 새로운 커밋을보아야합니다.
- 22. 명령 줄을 사용하여 GitBlit에서 공동 작업자를 repo에 추가하는 방법은 무엇입니까?
- 23. 포크로 연결된 cdnjs repo에 라이브러리를 추가하는 방법은 무엇입니까?
- 24. 마지막 n 패치를 git에서 repo에 추가하는 방법은 무엇입니까?
- 25. 파일을 repo에 업로드하는 방법은 무엇입니까?
- 26. 기존 리포지토리에 사전 푸시 git 훅을 추가하는 방법은 무엇입니까?
- 27. CCSprite의 위치를 CCParallaxNode에 추가하는 방법은 무엇입니까?
- 28. 로컬 repo에 원격 Git Repo를 추가하고 업데이트하는 방법?
- 29. xcode4 git repo에 액세스하는 동안 git push 오류가 발생했습니다.
- 30. 원격 Git Repo에 푸시 할 수 없습니다
잘 모르겠습니다. 기본적으로 Andrew가 지적한 것처럼 복제 된 Repo는 복제 된 원격을 ("origin"이라는 이름으로) 알고 있습니다. 그 이름을 대신 "업스트림"으로 지정 하시겠습니까 (이 경우 앤드류의 대답을 봐야합니다), 아니면 복제시 두 번째 리모컨을 추가하려고합니까? – Jubobs
원점이 분기 된 원본 Repo에 두 번째 리모컨을 추가합니다. 나는이 질문에 이것을 분명히했다. 모호함을 지적 해 주셔서 감사합니다! – holocronweaver