Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to copy a branch from one GitHub repository to another?

Tags:

git

branch

github

The Author had a respository, called Master.

I forked Master, and created branch A on it.
Then the Author created an Organization, forked Master to the Organization, and said that that should be the new official main repository.

Then he invited me to join the Organization and now I have commit access.

I'd like to copy my branch A onto the Organization repository so that it will have branch A, (ie. not integrating the branch,) but looking around, I can't seem to find any simple way to do this.

Both my version and the Organization version were forked from Master, so it should be pretty straightforward to copy the branch over, but everything I can find when I search for instructions online seems to be all about copying branches to your local copy of the repository, which isn't what I'm trying to do.

Does anyone know how to do this?

like image 520
Mason Wheeler Avatar asked Dec 20 '15 19:12

Mason Wheeler


1 Answers

I'd like to copy my branch A onto the Organization repository so that it will have branch A, (ie. not integrating the branch,) but looking around, I can't seem to find any simple way to do this.

Simply add the new remote (Organization) to your old repository (master).
Once you did it simply push the branch A to the new (organization) repository.

cd <old repository>
git remote add origin2 <new_url>
git push origin2 <branch A>

Now you should have the new branch A in your new repository.
The point is to add new remote and to push the branch to your new repository.

Second way id to update the current repository remote to point to the new location:

git remote set-url origin <new url>

And then push the branch.

Both of teh above will have the same result. The difference is that in the first one you add new remote while in the second one you change the remote.

enter image description here

like image 197
CodeWizard Avatar answered Oct 13 '22 23:10

CodeWizard