• git branch
    • 命令行参数
      • -d

    git branch

    git branch是分支操作命令。

    1. # 列出所有本地分支
    2. $ git branch
    3. # 列出所有本地分支和远程分支
    4. $ git branch -a

    (1)新建一个分支

    直接在git branch后面跟上分支名,就表示新建该分支。

    1. $ git branch develop

    新建一个分支,指向当前 commit。本质是在refs/heads/目录中生成一个文件,文件名为分支名,内容为当前 commit 的哈希值。

    注意,创建后,还是停留在原来分支,需要用git checkout切换到新建分支。

    1. $ git checkout develop

    使用-b参数,可以新建的同时,切换到新分支。

    1. $ git checkout -b NewBranch MyBranch

    (2)删除分支

    -d参数用来删除一个分支,前提是该分支没有未合并的变动。

    1. $ git branch -d <分支名>

    强制删除一个分支,不管有没有未合并变化。

    1. $ git branch -D <分支名>

    (3)分支改名

    1. $ git checkout -b twitter-experiment feature132
    2. $ git branch -d feature132

    另一种写法

    1. # 为当前分支改名
    2. $ git branch -m twitter-experiment
    3. # 为指定分支改名
    4. $ git branch -m feature132 twitter-experiment
    5. # 如果有重名分支,强制改名
    6. $ git branch -m feature132 twitter-experiment

    (4)查看 merge 情况

    1. # Shows branches that are all merged in to your current branch
    2. $ git branch --merged
    3. # Shows branches that are not merged in to your current branch
    4. $ git branch --no-merged

    命令行参数

    -d

    -d参数用于删除一个指定分支。

    1. $ git branch -d <branchname>