1

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

Jonny
  • 823
  • 3
  • 14
  • 25
  • 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 Answers3

1

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.

filbranden
  • 8,522
  • 2
  • 16
  • 32
0

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
Ru Chern Chong
  • 3,692
  • 13
  • 33
  • 43
-1

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

shahaf
  • 4,750
  • 2
  • 29
  • 32