Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating git branch based another branch

Tags:

git

git-branch

I'd like to create local branch based on other branch. For example I type:

git checkout -b feature1 release1.1.3

After that I get:

fatal: git checkout: updating paths is incompatible with switching branches.

What is the problem with this ?

like image 324
Leszek Andrukanis Avatar asked Feb 22 '13 14:02

Leszek Andrukanis


People also ask

Can I create a git branch from another branch?

Git provides us the capability to create a branch from another existing branch. Also, we can merge the branches using Git commands.

How do I make a branch match another branch?

To make a merge, you check out some branch ( A in these cases) and then run git merge and give it at least one argument, typically another branch name like B . The merge command starts by turning the name into a commit ID. A branch name turns into the ID of the tip-most commit on the branch.


2 Answers

git branch <new-branch-name> <existing-branch-name> 
like image 96
Arun Avatar answered Oct 04 '22 19:10

Arun


To create a branch based on another branch, the simplest way is to first checkout the base branch, then create a new branch from there. If I understand your question right, that's exactly what you want to do.

Now, seeing as you are using the -b flag in your branching, you may have working changes that you want to keep. If that's the case, you should push them onto the stash, check out the base branch, create the new branch, and pop the stash.

like image 36
ssube Avatar answered Oct 04 '22 19:10

ssube