git branch -r(--remotes )显示你本地仓库知道的所有 远程分支 的列表

好的,git branch -r 这个命令用于列出远程分支。让我详细解释一下:

命令:

bash 复制代码
git branch -r
bash 复制代码
dgq@dgqdeMac-mini ProductAuthentication % git branch -r
  origin/main

作用:

这个命令会显示你本地仓库知道的所有 远程分支 的列表。它不会显示你的本地分支,只显示远程仓库的分支。

输出格式:

输出通常会类似于这样:

复制代码
  origin/HEAD -> origin/main
  origin/develop
  origin/main
  origin/feature/new-feature
  origin/bugfix/fix-issue
  • origin/HEAD -> origin/main : 这表示远程仓库 origin 的 HEAD 指针指向 origin/main 分支。HEAD 指针通常表示远程仓库的默认分支(通常是 mainmaster)。
  • origin/develop, origin/main : 这些是远程仓库 origin 上的实际分支。origin/ 前缀表示它们是 origin 远程仓库的分支。

关键概念:

  • 远程仓库 (remote): 远程仓库是托管你的代码的版本库,通常托管在诸如 GitHub、GitLab、Bitbucket 等平台上。origin 是通常用来表示默认远程仓库的名称。
  • 远程分支 (remote branch): 远程分支是远程仓库中的分支的本地镜像。 它们以 远程仓库名称/分支名称 的形式显示,例如 origin/main。 远程分支是为了让你跟踪远程仓库的状态,方便你从远程仓库拉取更新或向远程仓库推送你的更改。
  • git branch -a vs git branch -r:
    • git branch -a 会列出所有的分支,包括本地分支和远程分支。
    • git branch -r 只列出远程分支。

使用场景:

  • 查看远程分支列表: 当你需要知道远程仓库上有哪些分支时,可以用这个命令。
  • 检查远程分支的 HEAD 指针: 查看远程仓库的默认分支。
  • 拉取远程分支: 在执行 git checkout -b <本地分支名> <远程分支名> 命令时, 你需要知道远程分支的名称。
  • 同步本地仓库和远程仓库:git fetch 后,你可以使用 git branch -r 来查看远程分支的最新状态。

总结:

git branch -r 是一个很有用的命令,可以让你查看和了解远程仓库的分支状态。它主要用于查看远程仓库中的分支信息,而不是你的本地分支。 它会让你明白远程仓库有哪些可用的分支,从而让你更好的组织你的本地开发工作。


git branch -r 中的 -r 的英文全称是 --remotes

所以,git branch -r 实际上是 git branch --remotes 的简写。

bash 复制代码
dgq@dgqdeMac-mini ProductAuthentication % git branch -help
usage: git branch [<options>] [-r | -a] [--merged] [--no-merged]
   or: git branch [<options>] [-f] [--recurse-submodules] <branch-name> [<start-point>]
   or: git branch [<options>] [-l] [<pattern>...]
   or: git branch [<options>] [-r] (-d | -D) <branch-name>...
   or: git branch [<options>] (-m | -M) [<old-branch>] <new-branch>
   or: git branch [<options>] (-c | -C) [<old-branch>] <new-branch>
   or: git branch [<options>] [-r | -a] [--points-at]
   or: git branch [<options>] [-r | -a] [--format]

Generic options
    -v, --verbose         show hash and subject, give twice for upstream branch
    -q, --quiet           suppress informational messages
    -t, --track[=(direct|inherit)]
                          set branch tracking configuration
    -u, --set-upstream-to <upstream>
                          change the upstream info
    --unset-upstream      unset the upstream info
    --color[=<when>]      use colored output
    -r, --remotes         act on remote-tracking branches
    --contains <commit>   print only branches that contain the commit
    --no-contains <commit>
                          print only branches that don't contain the commit
    --abbrev[=<n>]        use <n> digits to display object names

Specific git-branch actions:
    -a, --all             list both remote-tracking and local branches
    -d, --delete          delete fully merged branch
    -D                    delete branch (even if not merged)
    -m, --move            move/rename a branch and its reflog
    -M                    move/rename a branch, even if target exists
    -c, --copy            copy a branch and its reflog
    -C                    copy a branch, even if target exists
    -l, --list            list branch names
    --show-current        show current branch name
    --create-reflog       create the branch's reflog
    --edit-description    edit the description for the branch
    -f, --force           force creation, move/rename, deletion
    --merged <commit>     print only branches that are merged
    --no-merged <commit>  print only branches that are not merged
    --column[=<style>]    list branches in columns
    --sort <key>          field name to sort on
    --points-at <object>  print only branches of the object
    -i, --ignore-case     sorting and filtering are case insensitive
    --recurse-submodules  recurse through submodules
    --format <format>     format to use for the output
相关推荐
cc蒲公英6 小时前
idea git命令初次创建项目至远程
git
高兴就好(石7 小时前
git将远程的master分支的commit都拉取到本地
git
空空kkk9 小时前
Git版本控制(一)
git
毛豆的毛豆Y10 小时前
git 如何 fork 一个仓库的所有分支
git
测试人社区—841611 小时前
Postman API测试指南
人工智能·git·测试工具·自动化·bug·postman
芒克芒克13 小时前
『Git Tag标签+项目远程操作全解:推送、拉取与版本同步实战』
java·git
fruge14 小时前
前端工程化最佳实践:ESLint+Prettier+Git Hooks 统一开发规范
前端·git
_院长大人_14 小时前
解决 Git 提交大文件导致 Push 被拒绝的问题
java·git·后端·elasticsearch
浪潮IT馆14 小时前
win11安装Git
windows·git
SoulmateShkart15 小时前
Git基本使用命令简略版
git