여러 원격 위치에서 당기기 / 밀기
요약 : git repo가 원격 저장소 목록 (단일 "원본"이 아닌)으로 푸시하고 가져 오는 방법이 있습니까?
긴 시간 : 여러 대의 컴퓨터에서 서로 다른 연결을 사용하여 앱을 개발할 때 종종 상황이 발생합니다. 예를 들어 이동 중에는 랩톱, 특정 위치에있는 동안 컴퓨터 "A", 다른 컴퓨터 "B"와 같이 다른 동안. 또한 랩톱은 "A"또는 "B"중 하나로 만 연결될 수 있으며 때로는 둘 다에 연결될 수도 있습니다.
내가 원하는 것은 git이 현재 연결할 수있는 모든 컴퓨터에서 항상 "pull"하고 "push"하는 것이므로 한 컴퓨터에서 다른 컴퓨터로 이동하여 원활하게 계속 작업하는 것이 더 쉽습니다.
다음 git remote
명령을 사용하여 여러 원격 저장소를 구성 할 수 있습니다 .
git remote add alt alt-machine:/path/to/repo
구성된 모든 원격 및 업데이트 추적 분기에서 가져 오지만 HEAD에 병합하지 않으려면 다음을 수행하십시오.
git remote update
현재 리모컨 중 하나에 연결되어 있지 않으면 시간이 걸리거나 오류가 발생하고 다음으로 넘어갑니다. 수집 변경 사항을 구성하려는 방법에 따라 가져온 리포지토리에서 수동으로 병합하거나 체리 선택해야합니다.
alt에서 마스터 브랜치를 가져와 현재 헤드로 가져 오려면 다음을 수행하십시오.
git pull alt master
따라서 실제로 git pull
는 거의 약어입니다 git pull origin HEAD
(실제로이를 결정하기 위해 구성 파일을 살펴 보지만 아이디어를 얻습니다).
업데이트를 푸시하려면 각 저장소에 수동으로이를 수행해야합니다. 푸시는 중앙 저장소 워크 플로를 염두에두고 설계되었다고 생각합니다.
의 최신 버전에서는 이 작업을 더 이상 수동으로 수행 할 필요가 없습니다git
. 아래 Malvineous 의 솔루션을 참조하십시오 .
여기에 재현 :
git remote set-url origin --push --add <a remote>
git remote set-url origin --push --add <another remote>
원래 답변 :
이것은 나쁜 결과없이 꽤 오랫동안 사용해 왔으며 Linus Torvalds가 git 메일 링리스트 에 제안했습니다 .
araqnid 의 솔루션은 코드 를 저장소 로 가져 오는 데 적합한 솔루션입니다 .하지만 저처럼 권위있는 업스트림이 여러 개있는 경우 (저는 더 중요한 일부 프로젝트를 비공개 업스트림, GitHub 및 Codaset에 모두 복제합니다), 매일 변경 사항을 적용하는 것은 고통 스러울 수 있습니다.
간단히 말해서, git remote add
모든 리모컨을 개별적으로… 그런 다음 git config -e
병합 된 리모컨을 추가하십시오. 이 저장소가 있다고 가정합니다 config
.
[remote "GitHub"]
url = git@github.com:elliottcable/Paws.o.git
fetch = +refs/heads/*:refs/remotes/GitHub/*
[branch "Master"]
remote = GitHub
merge = refs/heads/Master
[remote "Codaset"]
url = git@codaset.com:elliottcable/paws-o.git
fetch = +refs/heads/*:refs/remotes/Codaset/*
[remote "Paws"]
url = git@github.com:Paws/Paws.o.git
fetch = +refs/heads/*:refs/remotes/Paws/*
… "Paws"
및 "Codaset"
에 대한 병합 된 원격을 만들기 위해 모든 항목 뒤에 다음을 추가 할 수 있습니다.
[remote "Origin"]
url = git@github.com:Paws/Paws.o.git
url = git@codaset.com:elliottcable/paws-o.git
이 작업을 수행하면 git push Origin Master
두 가지 모두 Paws/Master
에 Codaset/Master
순차적으로 푸시 되어 삶이 조금 더 쉬워집니다.
git 1.8 (2012 년 10 월)부터 명령 줄에서이 작업을 수행 할 수 있습니다.
git remote set-url origin --push --add user1@repo1
git remote set-url origin --push --add user2@repo2
git remote -v
그런 다음 git push
user1 @ repo1로 푸시 한 다음 user2 @ repo2로 푸시합니다.
이 별칭을 ~ / .bashrc에 추가했습니다.
alias pushall='for i in `git remote`; do git push $i; done;'
alias pullall='for i in `git remote`; do git pull $i; done;'
다음을 사용하여 리모컨을 추가 할 수 있습니다.
git remote add a urla
git remote add b urlb
그런 다음 모든 저장소를 업데이트하려면 다음을 수행하십시오.
git remote update
다음은 .gitconfig
별칭 섹션 내부에 bash 스크립트가있는 예제입니다.
[alias]
pushall = "!f(){ for i in `git remote`; do git push $i; done; };f"
I added two separate pushurl to the remote "origin" in the .git congfig file. When I run git push origin "branchName"
Then it will run through and push to each url. Not sure if there is an easier way to accomplish this but this works for myself to push to Github source code and to push to My.visualStudio source code at the same time.
[remote "origin"]
url = "Main Repo URL"
fetch = +refs/heads/*:refs/remotes/origin/*
pushurl = "repo1 URL"
pushurl = "reop2 URl"
I took the liberty to expand the answer from nona-urbiz; just add this to your ~/.bashrc:
git-pullall () { for RMT in $(git remote); do git pull -v $RMT $1; done; }
alias git-pullall=git-pullall
git-pushall () { for RMT in $(git remote); do git push -v $RMT $1; done; }
alias git-pushall=git-pushall
Usage:
git-pullall master
git-pushall master ## or
git-pushall
If you do not provide any branch argument for git-pullall then the pull from non-default remotes will fail; left this behavior as it is, since it's analogous to git.
You'll need a script to loop through them. Git doesn't a provide a "push all." You could theoretically do a push in multiple threads, but a native method is not available.
Fetch is even more complicated, and I'd recommend doing that linearly.
I think your best answer is to have once machine that everybody does a push / pull to, if that's at all possible.
For updating the remotes (i.e. the pull
case), things have become easier.
The statement of Linus
Sadly, there's not even any way to fake this out with a git alias.
in the referenced entry at the Git mailing list in elliottcable's answer is no longer true.
git fetch
learned the --all
parameter somewhere in the past allowing to fetch all remotes in one go.
If not all are requested, one could use the --multiple
switch in order to specify multiple remotes or a group.
add an alias to global gitconfig(/home/user/.gitconfig) with below command.
git config --global alias.pushall '!f(){ for var in $(git remote show); do echo "pushing to $var"; git push $var; done; }; f'
Once you commit code, we say
git push
to push to origin by default. After above alias, we can say
git pushall
and code will be updated to all remotes including origin remote.
I wanted to work in VSO/TFS, then push publicly to GitHub when ready. Initial repo created in private VSO. When it came time to add to GitHub I did:
git remote add mygithubrepo https://github.com/jhealy/kinect2.git
git push -f mygithubrepo master
Worked like a champ...
For a sanity check, issue "git remote -v" to list the repositories associated with a project.
C:\dev\kinect\vso-repo-k2work\FaceNSkinWPF>git remote -v
githubrepo https://github.com/jhealy/kinect2.git (fetch)
githubrepo https://github.com/jhealy/kinect2.git (push)
origin https://devfish.visualstudio.com/DefaultCollection/_git/Kinect2Work (fetch)
origin https://devfish.visualstudio.com/DefaultCollection/_git/Kinect2Work (push)
Simple way, worked for me... Hope this helps someone.
Adding the all
remote gets a bit tedious as you have to setup on each machine that you use.
또한, bash
및 git
별칭은 모두 당신이 밀어 버린다 있다고 가정 제공하는 모든 리모트. (예 : sshag
GitHub 및 GitLab에서 유지 관리 하는 포크가 있습니다. 업스트림 리모컨이 추가되었지만 푸시 할 권한이 없습니다.)
다음 은를 포함하는 푸시 URL을 사용하여 원격으로 만 푸시 하는 git
별칭 입니다 @
.
psall = "!f() { \
for R in $(git remote -v | awk '/@.*push/ { print $1 }'); do \
git push $R $1; \
done \
}; f"
새 리모컨 추가
git remote add upstream https://github.com/example-org/example-repo.git
git remote -vv
여러 위치에서 가져 오기
git fetch --all
위치로 푸시
git push -u upstream/dev
참고 URL : https://stackoverflow.com/questions/849308/pull-push-from-multiple-remote-locations
'development' 카테고리의 다른 글
객체 슬라이싱이란 무엇입니까? (0) | 2020.09.30 |
---|---|
컴파일러 작성법 배우기 (0) | 2020.09.30 |
변수 및 함수 이름에 대한 Python의 명명 규칙은 무엇입니까? (0) | 2020.09.30 |
목록에서 첫 번째 항목을 제거하는 방법은 무엇입니까? (0) | 2020.09.30 |
함수형 프로그래밍 대 객체 지향 프로그래밍 (0) | 2020.09.29 |