![git create branch from existing git create branch from existing](https://docs.looker.com/assets/images/dev-git-new-branch-718.png)
If this existing north branch is useful, don't delete it! If it's already checked out in some existing work-tree, move to that work-tree and work on it there. Now you don't have a local branch named north and you can create a new one.
![git create branch from existing git create branch from existing](https://assets.digitalocean.com/articles/git-integration-in-visual-studio-code/3.png)
If this existing north branch is not useful, you can delete it. But you already have a branch named north. You're running git worktree add in a way that is just like git checkout -b, except that the checkout occurs in the new added work-tree. This seems pretty natural: no one is ever surprised by this.
![git create branch from existing git create branch from existing](https://www.tutorialspoint.com/gitlab/images/create-branch-2.jpg)
By definition, a new branch name is automatically different from every existing branch name: $ git checkout -b newbranchįatal: A branch named 'newbranch' already exists. Hence, it's pretty typical to want to create a new branch name when creating a new work-tree.
GIT CREATE BRANCH FROM EXISTING HOW TO
Rather than trying to figure out how to deal with these-by either educating programmers or providing tools to deal with the problems- git worktree simply forbids the situation entirely. Having two different work-trees with independent index objects but the same underlying branch leads to some tricky problems for users to deal with. This is because, while each added work-tree has its own index and HEAD, the HEAD files wind up sharing the underlying branch pointers in the shared repository. north northįirst, a reminder (or information for others coming across this question): git worktree add wants to create a new work-tree and, at the same time, make sure that this new work-tree is using a different branch name from every other work-tree.
GIT CREATE BRANCH FROM EXISTING CODE
The two branches don't seem like they have diverged that much, so the risk of totally screwing up the code base is minimal.TL DR: you probably wanted git worktree add. Don't sweat this decision too much given the situation you described. If the comments branch has not been pushed yet, rebasing this branch on dev will rewrite the history of the comments branch to look as though it had been created from dev in the first place.Įven though it does matter which branch you create a new branch from, git allows you make corrections to the history of the branch prior to pushing it. If you added commits to the comments branch you can just merge dev into comments and move on with your life. If you created the comments branch from blog_posts and meant to create it from dev, merging dev into the comments branch results in a fast forward merge if no commits were added to the comments branch. So yes, it does matter which branch you create the new branch from, however.ĭon't worry too much about this. Upon creating the comments branch it will point to the tip of blog_posts, which would not contain the merge commit. I'm going to assume the git commands that were executed were roughly: git checkout devĪs of merging blog_posts into dev you could potentially create a merge commit in dev that does not exist in blog_posts if you have not merged the latest from dev into blog_posts. What you call "featureb" I will call "comments". What you call "featurea" I will call "blog_posts". Let's say you are building a blog web application. I always work better with concrete names, so I will make up a few branches.