programing tip

Git 1.7+의 모든 원격 브랜치를 어떻게 나열합니까?

itbloger 2020. 10. 4. 10:40
반응형

Git 1.7+의 모든 원격 브랜치를 어떻게 나열합니까?


시도 git branch -r했지만 로컬에서 추적 한 원격 분기 만 나열됩니다. 내가없는 목록을 어떻게 찾습니까? (명령이 모든 원격 분기를 나열하는지 또는 추적 되지 않은 분기 만 나열하는지 여부는 나에게 중요하지 않습니다 .)


여기 방문자의 대다수 [1] 에게 "Git 1.7+의 모든 원격 브랜치를 어떻게 나열합니까?"라는 질문에 대한 정확하고 간단한 대답입니다. is :

git branch -r

소수의 경우 [1] git branch -r 이 작동하지 않습니다. 만약 git branch -r하지 작업 시도하지 :

git ls-remote --heads <remote-name>

경우 git branch -r없는 작업을 수행 어쩌면로 Cascabel는 말한다 "당신이 그렇게하는 것이 기본 refspec을 수정 한 git fetchgit remote update모든 가져 오지 않습니다 remote의 가지를" .


[1] 2018-2 월이 각주를 작성하는 시점에서 댓글을 살펴본 결과 git branch -r대다수 ( 140 약 90 % 또는 125)가 작업하는 것을 확인했습니다.

경우 git branch -r없는 작업을 수행, 검사는 git config --get remote.origin.fetch와일드 카드 (포함 *에 따라) 이 답변


remote show 로컬에서 추적되지 않은 분기와 아직 가져 오지 않은 분기를 포함하여 원격의 모든 분기를 표시합니다.

git remote show <remote-name>

또한 로컬 저장소와 관련된 브랜치의 상태를 표시하려고합니다.

> git remote show origin
* remote origin
  Fetch URL: C:/git/.\remote_repo.git
  Push  URL: C:/git/.\remote_repo.git
  HEAD branch: master
  Remote branches:
    branch_that_is_not_even_fetched new (next fetch will store in remotes/origin)
    branch_that_is_not_tracked      tracked
    branch_that_is_tracked          tracked
    master                          tracked
  Local branches configured for 'git pull':
    branch_that_is_tracked merges with remote branch_that_is_tracked
    master                 merges with remote master
  Local refs configured for 'git push':
    branch_that_is_tracked pushes to branch_that_is_tracked (fast-forwardable)
    master                 pushes to master                 (up to date)

git branch -a | grep remotes/*

사용 git branch -r은 모든 원격 분기를 git branch -a나열하고 로컬 및 원격의 모든 분기를 나열합니다. 이 목록은 구식입니다. 이 목록을 최신 상태로 유지하려면 다음을 실행하십시오.

git remote update --prune

원격의 모든 새 항목으로 로컬 분기 목록을 업데이트하고 더 이상 존재하지 않는 항목을 제거합니다. --prune없이이 업데이트 명령을 실행하면 새 분기가 검색되지만 더 이상 원격에없는 분기는 삭제되지 않습니다.

리모컨을 지정하여이 업데이트 속도를 높일 수 있습니다. 그렇지 않으면 추가 한 모든 리모컨에서 업데이트를 가져옵니다.

git remote update --prune origin

그러나

git branch -ar

해야합니다.


당신은 또한 할 수 git fetch다음에 git branch -r. 가져 오기 없이는 최신 브랜치를 볼 수 없습니다.


Git 분기-원격 분기

git ls-remote

힘내 문서 .


내가 찾은 가장 간단한 방법 :

git branch -a

TL; TR;

이것이 문제의 해결책입니다.

git remote update --prune    # To update all remotes
git branch -r                # To display remote branches

또는:

git remote update --prune    # To update all remotes
git branch <TAB>             # To display all branches

The best command to run is git remote show [remote]. This will show all branches, remote and local, tracked and untracked.

Here's an example from an open source project:

> git remote show origin
* remote origin
  Fetch URL: https://github.com/OneBusAway/onebusaway-android
  Push  URL: https://github.com/OneBusAway/onebusaway-android
  HEAD branch: master
  Remote branches:
    amazon-rc2                   new (next fetch will store in remotes/origin)
    amazon-rc3                   new (next fetch will store in remotes/origin)
    arrivalStyleBDefault         new (next fetch will store in remotes/origin)
    develop                      tracked
    master                       tracked
    refs/remotes/origin/branding stale (use 'git remote prune' to remove)
  Local branches configured for 'git pull':
    develop merges with remote develop
    master  merges with remote master
  Local refs configured for 'git push':
    develop pushes to develop (local out of date)
    master  pushes to master  (up to date)

If we just want to get the remote branches, we can use grep. The command we'd want to use would be:

grep "\w*\s*(new|tracked)" -E

With this command:

> git remote show origin | grep "\w*\s*(new|tracked)" -E
    amazon-rc2                   new (next fetch will store in remotes/origin)
    amazon-rc3                   new (next fetch will store in remotes/origin)
    arrivalStyleBDefault         new (next fetch will store in remotes/origin)
    develop                      tracked
    master                       tracked

You can also create an alias for this:

git config --global alias.branches "!git remote show origin | grep \w*\s*(new|tracked) -E"

Then you can just run git branches.


With GitBash, you Can use:

git branch -a


try this....

git fetch origin
git branch -a

Make sure that the remote origin you are listing is really the repository that you want and not an older clone.


I ended up doing a mess shell pipeline to get what I wanted, just merged branches from the origin remote:

git branch -r --all --merged \
    | tail -n +2 \
    | grep -P '^  remotes/origin/(?!HEAD)' \
    | perl -p -e 's/^  remotes\/origin\///g;s/master\n//g'

Using this Command,

git log -r --oneline --no-merges --simplify-by-decoration --pretty=format:"%n %Cred CommitID %Creset: %h %n %Cred Remote Branch %Creset :%d %n %Cred Commit Message %Creset: %s %n"


CommitID       : 27385d919 
Remote Branch  : (origin/ALPHA) 
Commit Message :  New branch created

List all remote branches including commit messages,commit Id that are referred by remote branches.


I would use:

git branch -av

This command not only shows you the list of all branches, including remote branches starting with /remote but provides you the * feedback on what you updated and the last commit comments.


If there's a remote branch that you know should be listed, but it isn't getting listed, you might want to verify that your origin is set up properly with this:

git remote show origin

If that's all good, maybe you should run an update:

git remote update

Assuming that runs successfully, you should be able to do what the other answers say:

git branch -r

Just run a git fetch command. It will pull all the remote branches to your local repo and then do a git branch -a to list all the branches.


try

 git branch -at

참고URL : https://stackoverflow.com/questions/3471827/how-do-i-list-all-remote-branches-in-git-1-7

반응형