

So this command will do both the two things one is it will create a new branch and it will switch to that branch. We can use below command git checkout –b Instead of creating a new branch and then doing a checkout to switch to that branch create a new branch and switch to that branch In the above step I created devops branch and I switched to it. So it will switch from master to devops branch and by using this command we can switch to already existed branch only. To switch from one branch to another branch we use git checkout command git checkout If you have any comments or corrections please feel free to email them to me.So it will create a branch name called devops, and now you can check whether the branch is created or not by listing all branches with git branch command. You need to run git version 1.7.2 or higher in order for the -orphan option to be supported.

Using the checkout command you can switch back and forth between the different branches like this (just like if you where switching between directories): $ git checkout master

If you take a look at the log, you will see that it is isolated from the original log.

Now you can start adding files and commit them and they will live in their own branch. Since you want to create a new empty branch that has nothing to do with the original branch, you can delete all files in the new working directory: $ git rm -rf. The -orphan command keeps the index and the working tree files intact in order to make it convenient for creating a new history whose trees resemble the ones from the original branch. After running the above command you are on a new branch "foo", and the first commit you create from this state will start a new history without any ancestry. orphan creates a new branch, but it starts without any commit. You can create a new empty branch like this: $ git checkout -orphan foo Normally branches share files from the directory, but in Git it is possible to create empty branches. In Git you can have it all in one repository and keep things separated and isolated in branches. If the project is a web application with a database backend perhaps a backup of the SQL code is kept in yet another repository. In many coding projects the code is kept in one repository and the documentation is kept in another. | about | faq | hire me | contact | rss How to Create a New and Empty Branch in Git How to Create a New and Empty Branch in Git
