'Mirror a specific branch into another repo under a different branch name
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
Solution 1:[1]
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:
- Go the the GitHub website for RepoB
- Click Branches
- Click Change Default Branch
- Select the master branch
- Click Update
Now, the Branch2 of the RepoA branch is the master branch on RepoB with all the commit history and tags
Solution 2:[2]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | KarateTD |
| Solution 2 | Peter L |
