首页 > 解决方案 > Moving branch from one remote repo to another

问题描述

How do I move a branch (C) from one remote repo (A) to another remote repo (B)? Both master branches of the repos contains contains 2 initial commits: a README commit made while creating it on Github, another when creating an Angular project, so the directory structure is pretty much the same.

       C1--C2--C3--C4                 C1--C2--C3--C4
      /                  TO          /
A1--A2                         B1--B2

I tried using git remote set-url origin URL followed by a git pull origin master --allow-unrelated-histories. This lead to a few merge conflicts, all of which were resolved by accepting the incoming changes. But upon using git status it says the local master branch is ahead of origin/master is ahead by 3 commits, as well as own branch (C) being ahead of origin/C by 3 commits when it doesn't even have a corresponding branch in the remote repo yet.

I used git reset --hard HEAD~1 on the master branch to revert to the commit made before merging, so I can merge it properly this time.

What is causing this problem, and how can it be rectified? Also please tell me if you need more info, I'm new to git.

标签: git

解决方案


The simplest answer is that you should force-push the old branch into the new repository so that you get the exact same branch (content and history) into the new repo. That is what I would do, for sure.


推荐阅读