Last updated 2022-07-14 12:33:28

How To Turn A Git Branch To A Repository

01: ▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄ 02: ▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌ 03: ▐░█▀▀▀▀▀▀▀▀▀ ▀▀▀▀█░█▀▀▀▀ ▀▀▀▀█░█▀▀▀▀ 04: ▐░▌ ▐░▌ ▐░▌ 05: ▐░▌ ▄▄▄▄▄▄▄▄ ▐░▌ ▐░▌ 06: ▐░▌▐░░░░░░░░▌ ▐░▌ ▐░▌ 07: ▐░▌ ▀▀▀▀▀▀█░▌ ▐░▌ ▐░▌ 08: ▐░▌ ▐░▌ ▐░▌ ▐░▌ 09: ▐░█▄▄▄▄▄▄▄█░▌ ▄▄▄▄█░█▄▄▄▄ ▐░▌ 10: ▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌ ▐░▌ 11: ▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀ ▀ 12:

There are many reasons to convert a branch to a repository.

For example, you might want to start a new project with the same base as your current project.

Typically you will create a fork of the old project. However, this works if you know ahead of time that both projects will diverge going forward.

Sometimes you don't know they will diverge so you create a branch instead, this allows you to have a single copy of the project with the differences handled using branches.

But as your new branch begins to diverge more and more it only makes sense to have it as a repository.

Here is how to do that.

First, you need to create a remote repository for your new project eg: On GitHub [↗]. Make sure the repository is empty, so don't add a README file or license.

Run the following command to copy the branch over to the new repository:

$ git push <remote-url> <branch_to_copy_from>:<branch_to_copy_to>

< remote-url > is the URL pointing to the new repository you created. It typically looks something like this https://github.com/EDDYMENS/new-repo.git

< branch_to_copy_from > is the name of the branch you will like to convert to a repository.

< branch_to_copy_to > will be a branch on the new repository. If you haven't created any new branches yet you can use the default branch. It's usually main or master for most Git hosting platforms.

Here is another article you might like 😊 "Diary Of Insights: A Documentation Of My Discoveries"