I want to do something like this. I have a branch called branchA and i want to create a new branch. This new base if the new branch should be the master. How can i do this if i am working in the branchA
-
Possible duplicate of [Create Git branch with current changes](https://stackoverflow.com/questions/3899627/create-git-branch-with-current-changes) – Ru Chern Chong Apr 02 '18 at 05:08
3 Answers
Pass git branch
an extra argument indicating where to start from:
git branch branchB master
This will create a new branch branchB
which will start where master
currently points.
It won't switch branches, so if you're working on branch branchA
, you will stay there... If you want to create a new branch and start working on it too, then use checkout
with the -b
argument for the branch name. You can also pass it an extra argument with the starting point:
git checkout -b branchB master
You can also pass a starting point from a remote by using a syntax such as origin/master
.

- 8,522
- 2
- 16
- 32
This could already be a possible duplicate, but the quick way to creating a new branch from your master
branch can be done in the following.
On your master
branch,
$ git checkout -b new-branch-name
If not on your master
branch,
$ git checkout master
$ git checkout -b new-branch-name

- 3,692
- 13
- 33
- 43
the git flow is as follow
change branch to master from branchA
git checkout master
pull to update
git pull
create and swap to new branch
git checkout -b new-branch

- 4,750
- 2
- 29
- 32