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

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

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

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"
5. In c:\MyBranch, push MyBranch repo to NewRepo/MyBranch with the command: "git push 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

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.

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
Community showcase
Published in Bitbucket

New improvements to user management in Bitbucket Cloud 👥

Hey Community! We’re willing to wager that quite a few of you not only use Bitbucket, but administer it too. Our team is excited to share that we’ll be releasing improvements throughout this month of...

3,741 views 10 16
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you