Create a branch without files from an existing repository.git


I want to create a branch without files for an existing repository.

What I have done, is this:

  • make a new branch
  • erase everything (less .git and .gitignore , that is, the files of my project, not those of control or those that general editors)
  • make git add .
  • and then do commit

But I think it's a brute force solution.


How do I create a branch without files of an existing project?


Bonus: My repository is in , is there a specific way to achieve this for this specific platform? If it exists, what is it?

asked by toledano 14.03.2017 в 19:16

2 answers


There is an option called orphan for the git checkout command to do what I think you need that in itself is:


Create a branch without files from an existing repository

Your description in English


Create a new orphan branch, named <new_branch> , started from    <start_point> and switch to it. The first commit made on this new   branch will have no parents and it will be the root of a new history   totally disconnected from all the other branches and commits.

Translation (personal (if you have a better feel free to edit my answer))


Create an orphan branch, called <nueva_rama> , started from    <punto_de_inicio> and change it to this. The first commit done in   this new branch will not have parents and will be the root of a new story   totally disconnected from all other branches and commits

For which in conclusion you could do the following:

// Aquí creamos nuestra rama sin padre, independiente y sin historia
// pero con los archivos 'track' y 'untrack' que tengamos
// actualmente en nuestro directorio 
git checkout --orphan nueva_rama_independiente_de_todas_las_otras

(The above is thanks to the user's clarification sstan )

// Como los archivos seguirán presentes después de crear la rama
// procedemos a eliminar todos los archivos que han sido y/o estado
// 'track' y 'untrack'
git rm --cached -rf .

(The above is thanks to the user's advice (very useful and true by the way) Jhd )

Note that it is not necessary to use the -b option since when using --orphan it will go from the current branch to the one created as it can be read in the description of this option.

answered by 14.03.2017 / 19:32

Just make another branch apart from the master and develop with nothing so that you do not affect what you have in productive and development. and from that same branch that you do eliminate everything and comiteas

so you just leave the important branches intact

answered by 14.03.2017 в 19:35