Reputation: 29084
I have a repository in GitHub. I have made a lot of changes in local and if I push it now, I will get a lot of conflicts. So I decided to create a new branch, but I would like this branch to look like a new repository, so that I have two different versions in git under two different branches. How do I do that?
Need some guidance on this... Sorry if it is a noob question...
Upvotes: 1
Views: 616
Reputation: 49553
If I understood your question correctly, I believe you're looking for an orphan branch, a branch which has no parent, and helps you start a fresh set of commits not related to any other commit.
From the man page of git checkout
:
--orphan
Create a new orphan branch, named , started from 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.
The index and the working tree are adjusted as if you had previously run "git checkout ". This allows you to start a new history that records a set of paths similar to by easily running "git commit -a" to make the root commit.
This can be useful when you want to publish the tree from a commit without exposing its full history. You might want to do this to publish an open source branch of a project whose current tree is "clean", but whose full history contains proprietary or otherwise encumbered bits of code.
If you want to start a disconnected history that records a set of paths that is totally different from the one of , then you should clear the index and the working tree right after creating the orphan branch by running "git rm -rf ." from the top level of the working tree. Afterwards you will be ready to prepare your new files, repopulating the working tree, by copying them from elsewhere, extracting a tarball, etc.
These are the steps to achieve that:
git checkout --orphan my-new-orphan-branch
git rm -rf .
< Create your new files here >
git add <FILE1> <FILE2> ...
git commit -m 'Initial commit'
# Push the changes into the remote named origin
git push origin my-new-orphan-branch
Upvotes: 4