

To create empty branch, you have to go to terminal and execute: git checkout -orphan branchname git rm -rf. git checkout name tries to check out an existing branch using the name name. They cant create it using GUI, because SourceTree can create branch only from working copy parent or specified commit. This fails if the branch name already exists. Ocasionally, you may want to keep branches in your repository that do not share an ancestor with your normal code. git checkout -b name tries to create a new branch name name, using the current (HEAD) commit as the hash ID for the new branch. If your Git is older than 1.7.2 (when git checkout -orphan was introduced), then you can use the alternate command sequence from “Creating New Empty Branches” in the Git Community Book: Git commit -m 'Initial commit for version 2' You might use it like this: git checkout -orphan version2 Checking out a branch updates the files in the working directory to match the version stored in that branch, and it tells Git to record all new commits on that branch. In this case you can use the -track or -no-track options. Checking out branches The git checkout command lets you navigate between the branches created by git branch. Without -b, git checkout still sometimes creates a new branch When you leave out -b, git checkout name will first test to see if name matches some existing branch. The first commit made on this new branch will have no parents and it will be the root of a new history totally disconnected from all the other branches and commits. Specifying -b causes a new branch to be created as if git-branch1 were called and then checked out.
Git create new branch without checkout manual#
The manual for git checkout describes to work of the option -orphan:Ĭreate a new orphan branch, named, started from and switch to it. Which I think would agree with ctcherry's answer as well.īut if you really do want to create a completely different "branch" that is unrelated to master, then you can do it with git checkout -orphan.

Currently, the all-encompassing command git checkout does many things. Why don't you create two branches and add the two other versions to them and then work on the branches? git switch branch Git 2.23 came up with the new ‘ git switch ’ command, which is not a new feature but an additional command to ‘ switch/change branch’ feature which is already available in the overloaded git checkout command.
