-2

I have created a new branch in my project. But what i need now is to back to the Master and create a new branch. How can I do that with git ?

gh.amani
  • 31
  • 8
  • Are you looking for `git checkout master`? – wjandrea Jun 11 '19 at 14:50
  • 1
    `git checkout some-branch`. If you want to create a new branch from another: `git branch new-branch old-branch`. If you would like to create anew branch from another _and checkout_, `git checkout -b new-branch another-branch`. – eftshift0 Jun 11 '19 at 14:51
  • 1
    Possible duplicate of [How to switch back to 'master' with git?](https://stackoverflow.com/questions/7417166/how-to-switch-back-to-master-with-git) – Daan Jun 11 '19 at 14:53
  • @wjandrea no , how can I back to the master (the origin) and then create my new branch from the top – gh.amani Jun 11 '19 at 15:00

2 Answers2

2

For example:

git checkout -b new_branch origin/master
Martin G
  • 17,357
  • 9
  • 82
  • 98
  • It would probably be helpful if you could explain what this does. This would 1) Create a new branch based on the "master" branch with name "new_branch" and 2) checkout to the new branch. – Daan Jun 11 '19 at 15:00
1

Firstly check out master

git checkout master

Take latest changes from master

git pull origin master

Now, create new branch from master

git checkout -b newBranch
wjandrea
  • 28,235
  • 9
  • 60
  • 81
asingh8
  • 36
  • 3