Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git push all branches from one remote to another remote

Tags:

git

github

gitlab

I have two remote: upstream and origin. upstream is something I can't push to. origin is my own repo. How can I fetch all branches from upstream and then push them to origin? I tried:

git fetch upstream git push --all origin 

But it doesn't work.

like image 743
Tao Huang Avatar asked Jun 17 '16 15:06

Tao Huang


People also ask

How do I push all branches from one remote to another?

In some cases, you may want to push your changes to another branch on the remote repository. In order to push your branch to another remote branch, use the “git push” command and specify the remote name, the name of your local branch as the name of the remote branch.

Will git push push all branches?

No, git push only pushes commits from current local branch to remote branch that you specified in command.

Which command allows pushing all the branches to remote repository?

The git push command allows you to send (or push) the commits from your local branch in your local Git repository to the remote repository. To be able to push to your remote repository, you must ensure that all your changes to the local repository are committed.


2 Answers

You may want to try cloning your upstream repo with --mirror option and then push to your new remote with --mirror option too

You'll have the following flow:

git clone <upstream-repo-url/repo.git> --mirror cd <repo> git remote add <your-remote-name> <your-remote-url/repo.git> git push <your-remote-name> --mirror 

⚠ Be really careful with the push --mirror as it will delete branches that are on your <your-remote-name>

like image 82
Nicko Glayre Avatar answered Sep 17 '22 18:09

Nicko Glayre


I just needed to copy one repository from Bitbucket to GitHub, these are the steps assuming your remote is called origin, all branches and tags will be copied:

git remote add neworigin url-to-new-remote git push neworigin --tags "refs/remotes/origin/*:refs/heads/*" 

Good thing about this is that files in your working copy won't be modified.

like image 29
jose.arias Avatar answered Sep 19 '22 18:09

jose.arias