Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a new empty branch for a new project

We are using a git repository to store our project. We have our branches departing from the original branch. But now we want to create a small new project to track some documentation. For that we would want to create a new empty branch to start storing our files, and I would want other users of the network to clone that branch.

How can we do that?

I tried some things, but they didn't work.

$ mkdir proj_doc; cd proj_doc $ git init $ git add . $ git commit -m 'first commit' $ git br proj_doc $ git co proj_doc $ git br -d master $ git push origin proj_doc 

It seems to push the branch ok, but when I do a fetch or pull, it downloads information from other branches, and then I also get some extra files from other projects. What's the best solution?

like image 346
fazineroso Avatar asked Dec 20 '12 09:12

fazineroso


People also ask

Can we create an empty branch in git?

To create empty branch, you have to go to terminal and execute: git checkout --orphan branchname git rm -rf . Only after that you may see the new branch on GUI. Please, add the feature for creating new empty (without parent) branches on GUI.

How do you create a new branch in a project?

New Branches The git branch command can be used to create a new branch. When you want to start a new feature, you create a new branch off main using git branch new_branch . Once created you can then use git checkout new_branch to switch to that branch.

How do I create an empty branch in github UI?

new empty git branch.md $ git checkout --orphan NEWBRANCH $ git rm -rf . --orphan creates a new branch, but it starts without any commit. After running the above command you are on a new branch "NEWBRANCH", and the first commit you create from this state will start a new history without any ancestry.

How do I create an orphan branch in git?

Create an Orphan Branch An orphan branch is a separate branch that starts with a different root commit. So the first commit in this branch will be the root of this branch without having any history. It can be accomplished by using the Git checkout command with the ––orphan option.


1 Answers

You can create a branch as an orphan:

git checkout --orphan <branchname> 

This will create a new branch with no parents. Then, you can clear the working directory with:

git rm --cached -r . 

and add the documentation files, commit them and push them up to github.

A pull or fetch will always update the local information about all the remote branches. If you only want to pull/fetch the information for a single remote branch, you need to specify it.

like image 91
Hiery Nomus Avatar answered Sep 27 '22 21:09

Hiery Nomus