> For the complete documentation index, see [llms.txt](https://wikinote.gitbook.io/git-learning/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wikinote.gitbook.io/git-learning/git-ji-ben-ming-ling/fen-zhi-cao-zuo-yu-guan-li/git-branch.md).

# git branch

> git分支操作

## 查询当前分支清单

```
git branch [<--remote|--merged|--no-merged>]
```

* **无参数无选项**

  查询当前版本库所有分支清单
* **选项**
  * remote (显示远程分支)
  * merged (只显示已经与当前分支合并)
  * no-merged (只显示未与当前分支合并)

```bash
$ git branch
  iss53
* master
  testing
```

## 新建分支

```
git branch <branch_name>
```

* **参数**
  * branch\_name (分支名)

创建一个新的分支，仅仅是建立了一个新的分支，但HEAD不会自动切换到这个分支中去，请使用[git checkout命令](https://wikinote.gitbook.io/git-learning/git-ji-ben-ming-ling/fen-zhi-cao-zuo-yu-guan-li/pages/-LQoY-SoRy-SvARAGcDD#让HEAD切换到某个分支)或者\[git checkout -b命令]\[2]

## 删除分支

```
git branch -d|-D <branch_name>
```

* **参数**
  * branch\_name (分支名)
* **选项**
  * -d (安全删除)   &#x20;
  * -D (强制删除)

Git可删除其它非当前分支（HEAD所在的分支）的分支，-d是限定了只能删除与其它分支有合并过的分支，原因很简单，既然已经把它们所包含的工作整合到了其他分支，删掉也不会损失什么。

\[2]: git-checkout.md#新建一个分支，并让HEAD切换到这个分支上 "新建一个分支，并让HEAD切换到这个分支上"


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://wikinote.gitbook.io/git-learning/git-ji-ben-ming-ling/fen-zhi-cao-zuo-yu-guan-li/git-branch.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
