I have cloned a repository and created a branch (branch1
) off it.
I have a few changes in that branch.
Now I want to exit this branch, and create a new branch off of master
.
From what I understand, I can create a new branch using git branch myBranch
,
then switch to the branch by git checkout myBranch
.
But won't doing this create a new branch off the existing branch branch1
?
I want to exit my current branch (branch1
) and then create a new branch and enter it (myBranch
)
How can I do this?
You can do a
git checkout master
.
Then a
git checkout -b new_branch
git checkout -b foo
is the short form for git branch foo
and git checkout foo
afterwards.
Note that uncommitted changes will be still there on the new branch. If you have any conflicts because the files on master changed in the meantime, you can use git stash
to stash your current changes, checkout your new branch and do a git stash apply
afterwards. You need to resolve occuring conflicts on the new branch then.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With