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