Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a branch without adding all the existing files?

Tags:

git

When I create branch in git, all the created files are added to the new branch.

How can I create a branch without adding all the existing files?

like image 282
vinyuri Avatar asked Feb 23 '11 03:02

vinyuri


People also ask

How do I create a branch without losing changes?

The git checkout -b <BranchName> command will create a new branch and switch to it. Moreover, this command will leave the current branch as it is and bring all uncommitted changes to the new branch. There is no local change on the master branch, as we can see in the output.

Can you create a branch in an empty repository?

An empty repository cannot have a branch, branches are pointers to commits. So you first have to commit something in the empty repository before the branch can be created. You can either commit the code from the other repository, or just an empty file, create your branch and then commit the code.

Can I make a branch after making changes?

You can do a checkout and create a new branch with all local and current changes transferred over.


1 Answers

git checkout --orphan branchname git rm -rf . 

After doing that you can create, add, and commit new files and the resulting branch will have no common history with any other branches in your project (unless you merge them at some point).

like image 92
Arrowmaster Avatar answered Sep 18 '22 18:09

Arrowmaster