Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I exit my current branch?

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?

like image 750
A Nice Guy Avatar asked Dec 06 '22 15:12

A Nice Guy


1 Answers

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.

like image 101
buettner123 Avatar answered Dec 11 '22 08:12

buettner123