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
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
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.
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...
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