26

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 ?

manojlds
  • 259,347
  • 56
  • 440
  • 401
Leszek Andrukanis
  • 1,983
  • 2
  • 17
  • 28
  • Does `release1.1.3` exist? See this question http://stackoverflow.com/questions/945654/git-checkout-on-a-remote-branch-does-not-work. – Felix Kling Feb 22 '13 at 14:57

4 Answers4

32
git branch <new-branch-name> <existing-branch-name>
Arun
  • 18,092
  • 8
  • 46
  • 58
  • This answer sets up `new-branch-name` to track `existing-branch-name` from the remote, meaning if you push changes with this branch checked out, they will get pushed to a different branch on the remote. It's important to note that users need to follow up the branch creation with: `git push -u origin new-branch-name` in order to have the new branch track to an analogous branch on the remote. – DaBooba Jan 07 '21 at 03:40
19

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.

ssube
  • 41,733
  • 6
  • 90
  • 131
13

Do git pull first to make sure all you local branches are up-to-date. And then you can cut the branch.

The syntax is

$ git checkout -b <branch> --track <remote>/<branch>

or

$ git checkout <remote>/<branch> -b <branch>
zs2020
  • 52,221
  • 27
  • 148
  • 209
4

You meant git branch feature1 release1.1.3 assuming you want a branch called feature1 to be based upon the release1.1.3 commit. What you called there should also work but you also have an actual folder called 'release1.1.3' in your working tree and git is getting confused about whether you mean the branch/tag or the folder.

You could try just giving the actual commit id of release1.1.3.

patthoyts
  • 29,437
  • 2
  • 54
  • 84