Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How can I move a working branch from a repo to separate repository on its own?

Seetharama Sureshbabu January 4, 2021

I have been working a branch created long back in a repository. This has grown so big that it may never get merged to the trunk.  For better maintenance I want to covert this branch to a new repository but carrying the history so far.

Please advice how this could be achieved using Source Tree or even git command line. 

Thanks in advance

2 answers

0 votes
Seetharama Sureshbabu January 5, 2021

The suggestion didn't work out.

However I figured out a windy route to transfer the branch. This work fine for me on Windows (used Source tree and TortoiseGit to simplify some of the actions but given the equivalent commands here); should be ok on linux too.  Good luck.

AIM: Create a new repo called NewRepo from the branch MyRepo/MyBranch

1. Clone the work branch (e.g., MyBranch) from the work repo (MyRepo) to the local drive (c:\MyBranch)
2. Create an empty repo (e.g. NewRepo) in Bitbucket
3. In c:\MyBranch, reinitialise the git repo with the command: "git init"
4. In c:\MyBranch, change its remote URL to that of NewRepo with the command: "git remote set-url origin https://ACCOUNT_NAME@bitbucket.org/WORK_SPACE/NewRepo.git"
5. In c:\MyBranch, push MyBranch repo to NewRepo/MyBranch with the command: "git push https://ACCOUNT_NAME@bitbucket.org/WORK_SPACE/NewRepo.git MyBranch:MyBranch"
This will create a new branch called MyBranch in the remote repo NewRepo and push the files, folders and history from c:\MyBranch to NewRepo/MyBranch
6. Merge NewRepo/MyBranch to master. Remove the branch NewRepo/MyBranch if necessary

git.exe merge --allow-unrelated-histories remotes/origin/branch4
git.exe push --progress "origin" master:master

7. Now NewRepo will contain all the files, folders and history of MyRepo/MyBranch

0 votes
Joakim Wallman January 4, 2021

I'm having a similar issue.

I plan to use git filter-repo, but run into some issues, maybe we can solve them together.

Note that git filter-repo will rewrite history, so I will copy it to a new repo. Please read the documentation!

You can install git-filter-repo using python3 pip3:

pip3 install git-filter-repo
I only got it working under linux, where you might want to use sudo to get the correct install path.

then you need a fresh clone of your repository:

git clone --bare --mirror <path to your bitbucket repo>
bare will only checkout the .git folder, and mirror will include all references.

git filter-repo --path <path to remove> --invert-paths
Will remove the selected folder / files.

Create a new empty repo on bitbucket.

git remote add origin <path to new repo>

git push --mirror

After this it should be done, but bitbucket lists my repo size as a few kB and it fails to list branches.

Seetharama Sureshbabu January 4, 2021

My concern is not to corrupt the current repo as it contains few more active branches. 

Let me try with a test repo first.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events