Creating an Empty Branch

I want to create a new branch and upload a completely different code base while keeping the original codebase intact on the master branch. However when I attempted this I wound up with a second branch with the master branches code. How do I create an empty branch to upload my new codebase to?

2 answers

1 accepted

Hello,

From the git man pages, you can create a totally new line of history starting with the current version of all files by running:

git checkout --orphan branch-name

If you additionally do not want any of the files, you would then run:

git rm -rf .

Which would completely empty the current files. Be sure you are running git rm and not simply rm as you'll wipe out the .git directory and all your local history too!

You mean if I call "git rm" it would wipe out everything in the branch, cause thats what I'm trying to do, or do you mean that would wipe the whole repo (something I very much do not want to do)


Sorry for the super late reply.

I've found the solution, I just untracked everything added the new files in and then "git push -f origin [Branch Name]" and that worked.

git rm -rf .

Will remove everything from the working branch. As long as you have switched branches first, this is safe. Don't foget testing is as easy as making a copy/clone of the entire repo and trying it! Untracking everything and pushing probably isn't what you were looking to do unless you already committed all your files into the branch.

Hi,

 

Is there any way to do the same from EGit on Eclipse? 

 

Thanks in Advance.

Guess I'm gonna have to bump this

Suggest an answer

Log in or Join to answer
Community showcase
Piotr Plewa
Published Dec 27, 2017 in Bitbucket

Recipe: Deploying AWS Lambda functions with Bitbucket Pipelines

Bitbucket Pipelines helps me manage and automate a number of serverless deployments to AWS Lambda and this is how I do it. I'm building Node.js Lambda functions using node-lambda&nbsp...

711 views 0 4
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot