Reputation: 31
So I currently have 2 repos: RepoA and RepoB. I am being to asked to mirror RepoA:Branch2 into RepoB:Master. Is there a way to mirror all the commit history of RepoA:Branch2 into RepoB:Master.
All the examples I see keep the branch name the same or mirrors all the branches. I only need the one branch with all the history with a new branch name
I have tried mirroring and pushing but it copies everything. I have tried
Upvotes: 1
Views: 2687
Reputation: 3343
Single branch copied & renamed to another repo
Based on KarateTD's and some other sources...
mkdir branch2-only
cd branch2-only
git clone --single-branch --branch branch2 https://REPO_A_URL .
git remote add repo-b https://REPO_B_URL
git push repo-b branch2:master
Upvotes: 0
Reputation: 31
I found the answer over several examples
git clone --bare --single-branch --branch Branch2 https://github.com/stuff/RepoA.git
cd RepoA.git
git remote add newbranch https://github.com/otherstuff/RepoB
git push -u newbranch; git push --tags -u newbranch
cd ..
git clone https://github.com/otherstuff/RepoB.git
cd RepoB
git branch -m master
git push origin :Branch2 master
The last line will give you a warning that it can't delete Branch2 because it is the default. In order to fix that, you need to:
Now, the Branch2 of the RepoA branch is the master branch on RepoB with all the commit history and tags
Upvotes: 1