开发者

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

开发者 https://www.devze.com 2023-02-13 08:05 出处:网络
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?git checkout --orphan branchname

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?


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).


From the Git Book

git symbolic-ref HEAD refs/heads/newbranch 
rm .git/index 
git clean -fdx 
<do work> 
git add your files 
git commit -m 'Initial commit'


The current answers are correct, you'd need an orphaned branch, but I would just add that coincidentally...

This is actually exactly how github.com lets users create Github Pages for their repos, thru an orphaned branch called gh-pages. The pretty steps are given and explained here:

https://help.github.com/articles/creating-project-pages-manually

Hope this helps!

0

精彩评论

暂无评论...
验证码 换一张
取 消