0

Given I'm on first branch, tracking 'foo' and 'bar' files, like this:

my_repository/
            ./foo
            ./bar

How could I also track another branch (remote), where this 'foo' and 'bar' files are located under another location? I.e., when I checkout this second branch, my_repository folder turns into something like this:

my_repository/
            ./some_file
            ./another_file
            ./tests/
                 ../foo
                 ../bar

Explaining a bit more: I have first branch tracking a remote repository, and second branch tracking another remote repository.

In some point, I cloned second repository somewhere-else, added foo and bar files to tests folder, and commited it.

Then, I started commiting and making changes to my foo and bar files from my first branch, my oficial clone (origin/master). Now, I'd like to also send this changes to second repository, but not just overriding files's content. I'd like to have the commit history on the second branch too.

The problem is that this second repository place my files onto a different location.

Any tips?

madth3
  • 7,275
  • 12
  • 50
  • 74
Gabriel L. Oliveira
  • 3,922
  • 6
  • 31
  • 40
  • @Jan Yes, and does not worked like in your answer. I think I could put input less accuracy, so that git maybe realize they're same files, but I think that there are better ways to do this. – Gabriel L. Oliveira Aug 02 '11 at 08:24

2 Answers2

1

It looks like you are looking for the subtree merge strategy (see also here).

Francois G
  • 11,957
  • 54
  • 59
  • Thank you for this information, was really helpfull. Although I solved this by doing: First, checkout second branch, then `git merge master`, then `git mv` all files to the correct path of second branch, and then do a last `git commit` to say that you placed everything where it needed to be. Now I have two branches, where each one knows how to track and merge changes from same file, on different locations. :) – Gabriel L. Oliveira Aug 02 '11 at 08:19
0

There should not be any problem. There are two trees with some content. You merge them and put the files in one or another place in the merge and push that merge.

Git does not track file identities, but when it does a merge and notices a file that was modified on one side and does not exist on the other, it looks for files with sufficiently similar that the changes may have chance to apply. So if the files are similar, git will merge them (and you can move them to the other location if you wish), if they are different, it will just give you both and you'll have to choose (but than trying to merge them would be conflict anyway, so not tracking file identities did not loose anything).

Jan Hudec
  • 73,652
  • 13
  • 125
  • 172