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?
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.
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.
You can do a checkout and create a new branch with all local and current changes transferred over.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With