首页 > 解决方案 > When creating new branch, How to extend branch name from the existing branch (include example)

问题描述

for example, I have an existing branch that name is issue_12345

then I want to create another branch with naming issue_12345_features,

Is there an easy way to create a new branch referencing from the current branch name? (for example, Now I am in issue_12345 and want to create a branch starting from this current branch, the name start from the current branch name).

标签: gitgit-branch

解决方案


The following commands work in Bash and PowerShell.

Git 2.22 and above:

To just create a branch:

git branch "$(git branch --show-current)_features"

To create a branch and checkout to the new branch in a single command:

git checkout -b "$(git branch --show-current)_features"

Git version older than 2.2:

Replace git branch --show-current with git rev-parse --abbrev-ref HEAD:

git branch "$(git rev-parse --abbrev-ref HEAD)_features"

or

git checkout -b "$(git rev-parse --abbrev-ref HEAD)_features"

推荐阅读