Git list of branch names of specific remote

前端 未结 3 924
遥遥无期
遥遥无期 2021-01-31 08:15

How can it possible to get all names of some remote origin branches?

I started from --remote --list options, but got redundant origin/HEAD -> origi

3条回答
  •  萌比男神i
    2021-01-31 08:55

    The existing answer both uses something explicitly not wanted in the question (sed) and is a remote command.

    I found this that avoids both those issues, uses only local git commands and a pipe:

    git rev-parse --remotes=origin | git name-rev --name-only --stdin
    

    Update: Not really optimal either, but keeping it if someone knows how to improve it. It lists the full remote including the /remotes/origin prefix if you have no local branch, but only the local name if you have. In addition it seem to skip some refs if there are several pointing to the same SHA1.

提交回复
热议问题