How to push code of branchA to different repository branchB ?

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

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: https://github.com/Neptune998/NeptuneWorldA.git

BranchB Repo: https://github.com/Neptune998/NeptuneWorldB.git






Step1: 

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

 git clone https://github.com/Neptune998/NeptuneWorldA.git       


Now, checkout the branchA

git  checkout -b branchA


Now check the branch.

git branch -a

Step2:

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 https://github.com/Neptune998/NeptuneWorldB.git

Step3:

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