Get git-repository commit into different git-repository branch

2

Consider the following setup: One Repository1 sits on Bitbucket. A local working copy is situated on my machine. I change files locally, commit and push to Repository1.

Changes in Repository1 (on Bitbucket) (in "master" branch) where made only by me. Now I need to get some of these into a "feature"-branch of another Repository2, which also sits on Bitbucket.

The content of Repository2 however is newer, the changes made there by a remote team are not reflected in Repository1 nor my working copy of it. Repository2 contains also more files, where my Repository1 only contains a small portion of it.

In the end I want to have some of the changes in Repository1 ("master" branch) merged with the newer files in Repository2 ("feature" branch).

However, the only solution I'd know, is unpractial: Sorting out my changed files and manually diff & merge them, then copy them to my local working copy of Repository2, doing a commit & push afterwards.

Is there another method? Preferably something that includes auto-merge, where it's possible.

Thanks in advance!

Strongground

Posted 2014-02-25T13:46:41.893

Reputation: 21

Answers

1

There are two parts of your question: how to manage multiple repositories and how to do your merge.

Is there a reason you have two separate repositories on BitBucket, instead of a single repository with multiple branches? Assuming there is a good reason, you can still use your local repository to synch with two different remotes, something like

$ git fetch repo1 branch:master
$ git fetch repo2 branch:feature

This will create local branches master and feature, even if the branches in the remote repositories have the same name. After doing whatever you have to do with these branches, you can then push using a similar syntax:

$ git push repo1 master:branch
$ git push repo2 feature:branch

Once you have local copies of the branches, you should be able to merge your changes with

$ git checkout feature
$ git merge master

If there are conflicts, it is best to resolve them manually, but if you are sure that master is right, you can add the -s theirs option to the merge command.

benjifisher

Posted 2014-02-25T13:46:41.893

Reputation: 628

I managed to copy one change via patch. However, doing this regulary is not feasible. I will try your solution today. – Strongground – 2014-02-27T08:15:45.460