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

后端 未结 3 1640
天命终不由人
天命终不由人 2021-01-31 15:58

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?

相关标签:
3条回答
  • 2021-01-31 16:45

    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 讨论(0)
  • 2021-01-31 16:53

    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'
    
    0 讨论(0)
  • 2021-01-31 17:02
    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).

    0 讨论(0)
提交回复
热议问题