How to move branch from one repository to another branch of different repository
Asked Answered
E

4

19

I created a new Repository (named repoN) with the existing one (named repoE), simply by copying code from the branch (named B22).

After that, I created a new branch in repoN (named BR01). Now I made some changes in the branch (named BR01) which exist in repoN repository.

I just want to take all those changes into the old repository repoE without loosing history of BR01 into B22.

I am using SourceTree because I'm new in Git and don't know much commands.

Exhaust answered 30/6, 2016 at 9:5 Comment(1)
@Adnan: Have a look at this Meta question about adding bold fonts. (tl;dr: please don't do it.)Zounds
C
32
  1. stand on your current repo you want to push from and checkout the branch you want to push
  2. git remote add repoRemote https://bitbucket/repo/repo1.git
  3. git push repoRemote -- will push your current branch to the remote repo you added in #3
Curitiba answered 8/11, 2019 at 17:14 Comment(1)
Do we need to remove the destination repo with git remote remove repoRemote(not sure if the command is right) to switch to the existing repo once branch is transferred?Foreside
T
13

At first you need to add to git your destination repository, lets call it repoE ( set remote tracking )

git remote set-url repoE https://github.com/USERNAME/repoE.git

then switch to branch your want to push, assume your branch called BR01

git checkout BR01

and push this branch to destination repository

git push repoE BR01
Twibill answered 30/6, 2016 at 18:38 Comment(0)
R
2

In SourceTree, it can be done by adding repoE to Repository->Add Remote so that you can push the changes in repoN to that repo.

Resurrectionism answered 7/12, 2020 at 10:48 Comment(0)
R
1

Add the new remote URL: First, you need to add the new remote repository URL where you want to push your branch. You can do this using the git remote add command:

git remote add <remote_name> <remote_URL>


git remote -v
git push <remote_name> <branch_name>

Then direct to the new remote repository

git fetch
git checkout <branch_name>
Reins answered 15/4 at 12:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.