How to fetch only branch names from remote git repo?

Viewed 222

How can I get remote refs list (only names and commit id) without fetching objects?

WebUI is not answer obviously.

All that I found is remote HEAD name:

$ git remote -v show origin
* remote origin
  Fetch URL: https://git.git
  Push  URL: https://git.git
  HEAD branch: main
  Remote branch:
    refs/remotes/origin/master stale (use 'git remote prune' to remove)
  Local branch configured for 'git pull':
    master merges with remote master
1 Answers

You can use git ls-remote origin:

$ git ls-remote origin
670b81a890388c60b7032a4f5b879f2ece8c4558        HEAD
ebf3c04b262aa27fbb97f8a0156c2347fecafafb        refs/heads/maint
670b81a890388c60b7032a4f5b879f2ece8c4558        refs/heads/master
670b81a890388c60b7032a4f5b879f2ece8c4558        refs/heads/next
33bc620fd1829b92a6671b6bd65ee357447aa964        refs/heads/seen
2cbe4a3e125e059242544ae415ee82452eccc15b        refs/heads/todo

That lists the references, including branches and tags. If you want only branches, you can restrict it to things matching refs/heads: git ls-remote origin | grep refs/heads.

Related