CodeChimp
CodeChimp

Reputation: 8154

I messed up...moving a branch from one repo to another

I messed up. I thought I was being clever and created a single private repo on my GitHub account for all of my projects, thinking I could use branches for the various project development. I was being cheap because I only have 5 private repos on GitHub. Now I have a mess on my hand, and I am not sure how to "fix" it.

What I would like to do is take each branch and move it to it's own repo on BitBucket, ideally whilst maintaining the history for each branch. Each project is in a separate sub-folder and development was done within separate branches for each. I am hoping this separation will assist. Would anyone know how one might accomplish cleaning up this mess I have made?

Upvotes: 0

Views: 1582

Answers (1)

Damodaran
Damodaran

Reputation: 11065

You can add a new repository to your current repository by

git remote add <remote name> <repository url>

To list the remotes

git remote -v

To push a branch to a new repository

git push <remotename> <brancchname>

If you want to push a subfolder to a new repository refer the following site

Splitting a subfolder out into a new repository

To turn a folder within a Git repository into a brand new repository.

When splitting a folder into a separate repository, you won't lose any of your Git history or changes.

Open Terminal (for Mac and Linux users) or the command line (for Windows users). Change the current working directory to your local project. Run git filter-branch, making sure to include the name of the folder you want to separate.

git filter-branch --prune-empty --subdirectory-filter \
 YOUR_FOLDER_NAME master
# Filter the master branch to your directory and remove empty commits
# Rewrite 48dc599c80e20527ed902928085e7861e6b3cbe6 (89/89)
# Ref 'refs/heads/master' was rewritten

The repository now contains all the files that were in your subfolder. Note that although all of your previous files have been removed, they still exist within the Git history. You can choose to push your repository to a new remote, or act upon them in any other way you would normally.

git push my-new-repo -f .

Upvotes: 1

Related Questions