KarateTD
KarateTD

Reputation: 31

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

Upvotes: 1

Views: 2687

Answers (2)

Peter L
Peter L

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

KarateTD
KarateTD

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:

  1. Go the the GitHub website for RepoB
  2. Click Branches
  3. Click Change Default Branch
  4. Select the master branch
  5. Click Update

Now, the Branch2 of the RepoA branch is the master branch on RepoB with all the commit history and tags

Upvotes: 1

Related Questions