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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

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

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.

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

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Posted in Bitbucket

Contest: Share your custom Bitbucket Pipe and win

Announced in this blog, this holiday season we’re celebrating all things CI/CD and between now and the end of 2019 we’ll be showcasing content, use cases, feature announcements and more. One featur...

2,132 views 11 6
Join discussion

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