Merging branches from two different repos

Mauro Catellani January 7, 2025

Hi,

i have another question:

is it possible merge a branch named mybranch for example, from repo https://myuser@bitbucket.org/myuser/myrepo.git to

another repo https://myuser@bitbucket.org/myuser/myrepo1.git

the two repo are in the different URL

Kind regards

Mauro

1 answer

0 votes
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 8, 2025

Hi Mauro,

Just a heads up, I moved your reply to a new question as it concerned a different topic from the one discussed in your previous question.

If myrepo is a fork of myrepo1 then it's pretty straightforward to merge with a pull request from Bitbucket's website. If you open myrepo on Bitbucket's website, go to the Pull requests page, and select Create pull request, you will have the option to change the Destination Repository into myrepo1 and then select both a source branch and a destination branch for the PR.

If myrepo is not a fork of myrepo1, then there is no way to do the merge from Bitbucket's website. It is possible to do it locally in a clone of the repo, but you'll need to use the option --allow-unrelated-histories in the git merge command.

These are the steps to do this:

1. Clone myrepo1

git clone https://myuser@bitbucket.org/myuser/myrepo1.git

2. Switch to the directory of the clone and add a second remote that points to myrepo

cd myrepo1
git remote add second-remote https://myuser@bitbucket.org/myuser/myrepo.git

3. Run the following command to fetch updates from both repos

git remote update

4. Let's assume you want to merge mybranch from myrepo into mybranch1 of myrepo1. Check out mybranch from myrepo

git checkout -b mybranch --track second-remote/mybranch

5. Check out mybranch1 of myrepo1 and then do the merge

git checkout mybranch1
git merge --allow-unrelated-histories mybranch

Kind regards,
Theodora

Mauro Catellani January 8, 2025

Thanks a lot Theodora for your answer.

In the next days i try to does.

Kind Regards

Mauro

Like Theodora Boudale likes this
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 8, 2025

You are welcome, Mauro. Please feel free to let me know how it goes!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events