Development Tip

모든 브랜치를 당기고 밀도록 git 설정

yourdevel 2020. 10. 3. 12:02
반응형

모든 브랜치를 당기고 밀도록 git 설정


새로 생성 된 분기를 포함하여 기본적으로 모든 분기를 밀고 당기고 싶습니다.

정의 할 수있는 설정이 있습니까?

그렇지 않으면 새 브랜치를 로컬로 추가하고 서버에서 가져 오려고 할 때 가장 간단한 방법은 무엇입니까?

같은 이름으로 새 브랜치를 만들고 가져 오려고했지만 작동하지 않습니다. 분기의 모든 원격 구성을 요청합니다. 어떻게 설정합니까?


가장 간단한 방법은 다음과 같습니다.

git push --all origin

이렇게하면 태그와 분기가 푸시됩니다.


최신 git을 사용하면 항상 모든 분기를 가져옵니다 ( 또는로 refs/remotes/origin/*표시 되는 네임 스페이스 로의 원격 추적 분기로 ).git branch -rgit remote show origin

기본적으로 ( push.defaultconfig 변수 문서 참조 ) 일치하는 브랜치 를 푸시합니다. 즉, git push origin branchgit이 항상 푸시 하려면 먼저해야 합니다 git push.

당신이 할 경우 항상 모든 지점을 누르면 , 당신은 푸시 refspec을 설정할 수 있습니다. 리모컨의 이름이 지정되었다고 가정하면 git configorigin 를 사용할 수 있습니다 .

$ git config --add remote.origin.push '+refs/heads/*:refs/heads/*'
$ git config --add remote.origin.push '+refs/tags/*:refs/tags/*'

또는 .git/config다음과 같이 파일을 직접 편집 하십시오.

[원격 "원점"]
        URL = user@example.com : /srv/git/repo.git
        가져 오기 = + refs / heads / * : refs / remotes / origin / *
        가져 오기 = + refs / tags / * : refs / tags / *
        푸시 = + refs / heads / * : refs / heads / *
        푸시 = + refs / tags / * : refs / tags / *

푸시 사양에 +를 포함하는 것은 아마도 나쁜 생각 일 것입니다. git이 -f 없이도 비-빨리 감기 푸시를 기꺼이 수행 하고 원격 서버가이를 수락하도록 설정되어 있으면 기록을 잃을 수 있기 때문입니다.

이것을 시도하십시오 :

$ git config --add remote.origin.push 'refs/heads/*:refs/heads/*'
$ git config --add remote.origin.push 'refs/tags/*:refs/tags/*'
$ git config --add remote.origin.fetch 'refs/heads/*:refs/remotes/origin/*'
$ git config --add remote.origin.fetch 'refs/tags/*:refs/tags/*'

아래 명령을 사용하여 모든 분기를 새 저장소로 마이그레이션했습니다.

~$ git clone --mirror <url_of_old_repo>
~$ cd <name_of_old_repo>
~$ git remote add new-origin <url_of_new_repo>
~$ git push new-origin master
~$ git push new-origin --mirror

참고 : Atlassian Stash 에서 AWS CodeCommit (빈 리포지토리)으로 리포지토리 를 복제하는 동안 마지막 두 번째 (즉, push master first) 명령을 사용해야했습니다 . 이유는 확실하지 않지만 ( git push new-origin --mirror) 기본 분기를 누른 후 master.


이전 저장소에서 새 저장소로 브랜치를 이동하고 모든 이전 저장소 브랜치를 로컬에 가지고 있지 않은 경우 먼저 해당 저장소를 추적해야합니다.

for remote in `git branch -r | grep -v '\->'`; do git branch --track $remote; done

그런 다음 새 원격 저장소를 추가하십시오.

git remote add bb <path-to-new-repo>

그런 다음이 명령을 사용하여 모두 푸시 할 수 있습니다.

git push -u bb --all

또는이 작업을 한 번 수행하지 않거나 로컬 브랜치를 이동하려는 경우 여기에있는 다른 응답에 언급 된 git config 명령을 사용하여 저장소를 구성 할 수 있습니다.

중요한 점은 다른 응답은 모든 LOCAL 분기 만 푸시한다는 것입니다. 분기가 대체 REMOTE 저장소에만 존재하는 경우 먼저 추적하지 않고는 이동하지 않습니다. 여기에 제시된 for 루프가 도움이 될 것입니다.


out을 사용 git branch -a하지 않고 모든 분기를 보려면 다음을 실행해야합니다.

for remote in `git branch -r`; do git branch --track $remote; done
git fetch --all
git pull --all

이제 모든 분기를 볼 수 있습니다.

git branch

모든 분기를 밀려면 다음을 시도하십시오.

git push --all

If you are moving all branches to a new repo from an old one then in your local repo you need to set up tracking of each branch to existing origin branches, before pushing to the new repo, otherwise all your origin branches won’t appear in the new origin. Do this manually by tracking or checking out each branch, or use the one liner:

for remote in `git branch -r | grep -v '\->' | grep -v master`; do git branch --track `echo $remote|sed 's=origin/=='` `echo $remote`; done

This one line command is based on versions of it in other answers on this page, but is arguably better because:

  1. it correctly sets up the branch tracking, unlike some older variants of this command on this page which only supply one parameter to --track and thus each branch ends up tracking master - not good
  2. names the local branches without the prefix “origin/” which I personally don’t want - and is consistent with what happens when you checkout a branch normally.
  3. skips tracking master since that is already happening
  4. doesn’t actually checkout anything thus is fast
  5. avoids stumbling over the -> in the output of git branch -r

Next, if you are switching origins, replace the link to the old origin and point to a new remote. Ensure you create the new remote first, using bitbucket/github GUI, but don’t add any files to it or there will be a merge problem. E.g.

git remote set-url origin git@bitbucket.org:YOUR/SOMEREPO.git

Now push. Note the second command is needed to push the tags as well:

git push -u --all origin
git push --tags origin

Solution without hardcoding origin in config

Use the following in your global gitconfig

[remote]
    push = +refs/heads/*
    push = +refs/tags/*

This pushes all branches and all tags

Why should you NOT hardcode origin in config?

If you hardcode:

  1. You'll end up with origin as a remote in all repos. So you'll not be able to add origin, but you need to use set-url.
  2. If a tool creates a remote with a different name push all config will not apply. Then you'll have to rename the remote, but rename will not work because origin already exists (from point 1) remember :)

Fetching is taken care of already by modern git

As per Jakub Narębski's answer:

With modern git you always fetch all branches (as remote-tracking branches into refs/remotes/origin/* namespace

참고URL : https://stackoverflow.com/questions/1914579/set-up-git-to-pull-and-push-all-branches

반응형