How to push code of branchA to different repository branchB ?

Author: neptune | 22nd-Feb-2022 | Views: 510

We are going to push the code of branch(branchA) to a new branch(branchB) in a different repository.

branchA: Which you want to Push.

branchB: Where you want to Push.

Follow these steps:

  • Clone branchA locally in your machine.

  • Remove the remote origin from above cloned branchA.

  • Create a new branchB if not created yet.

  • Add remote origin of branchB repository.

  • Checkout branchB.

  • Then Commit changes if you make any.

  • Then Push the code in branchB.

Detailed Steps:

Clone URLs: 

BranchA Repo:

BranchB Repo:


Clone the existing repository from where you want to push the code i.e NeptuneWorldA .

 git clone       

Now, checkout the branchA

git  checkout -b branchA

Now check the branch.

git branch -a


Now we will remove the existing remote origin NeptuneWorldA and add remote origin NeptuneWorldB.

Check the remote origin:

git remote -v

git remote rm origin

Now add the origin of NeptuneWorldB.

git remote add origin


Check the remote origin.

git remote -v

git checkout -b branchB

Follow the steps we always do to push code.

git status

git add .

git commit -m “Commit msg”

git push -u origin branchB

If you get warning to pull and you don’t want to add the existing code then use -f tag. 

git push -u -f origin branchB

If you face any issue write in the comment section.

Thanks for Reading !

anonymous | Dec. 8, 2021, 10:12 a.m.

Brief and Short Great !

Related Blogs View More