Two GIT Projects

Asked

Viewed 982 times

2

If I have a project already being done in git and at some point I need to unite with another project but keep the histories of commit has as?

  • Yes, I did it to put together three distinct projects once.

  • you remember which commands?

  • i found this one and I’m trying, what do you think? https://stackoverflow.com/questions/1425892/how-do-you-mergetwo-git-repositories

  • The subtree has a distinct effect on my memory... I didn’t use it; I went out with traditional merge anyway, but it was because it satisfied my case better

  • Okay, you found the link I used initially: https://stackoverflow.com/a/10548919/4438007; when I went to test, man git did not accept the flag --allow-unrelated-histories, then I just ignored it and it worked. It was so long ago that I had even lost this link

  • I may be wrong, but I think . gitignore can help avoid updating things from different repositiorios.

  • @I just don’t know how to do it .gitignore for specific remotes (if that’s what you mean)

  • 1

    @Jeffersonqueso you’re right it wouldn’t work, I’m not sure but I think maybe this works https://stackoverflow.com/a/22906964/1518921

  • @Guilhermenascimento this is news to me, I’ve never been to touch inside the briefcase .git xD

  • 1

    @Jeffersonquesado I also not, so I did not kick answers, I think that by command line is much more practical, but we will see in time, if I have an opportunity I will test and leave as alternative answer

Show 5 more comments

1 answer

3

This was a necessity in the work, I had to join some repositories. I adapted what is in this answer, to remedy my problem. Thanks to AP for discovering the original link I had lost

Know that you will need a lot of discipline for this.

I’m going to talk about my experience joining 3 repositories into a new one, okay?

First step was to create the new repository to aggregate the others. I started this repository with an initial commit (from README.md same) to have a starting point. I created a new branch called raiz with this commit (I don’t change it, however).

So I added the desired remote repositories:

git remote add repo_old1 https://url/to/repo1
git remote add repo_old2 https://url/to/repo2

So here’s what I did:

git checkout raiz -b master
git merge repo_old1/master
mkdir repo1_dir
git mv {arquivos do repo1} repo1_dir/
git commit -m 'Sandboxando o repo1'

git merge repo_old2/master
mkdir repo2_dir
git mv {arquivos do repo2} repo2_dir/
git commit -m 'Sandboxando o repo2'

Then you need to do the same to develop it; in case, I started going to the branch raiz and doing the same operation:

git checkout raiz -b develop
git merge repo_old1/develop
mkdir repo1_dir
git mv {arquivos do repo1} repo1_dir/
git commit -m 'Sandboxando o repo1'

git merge repo_old2/develop
mkdir repo2_dir
git mv {arquivos do repo2} repo2_dir/
git commit -m 'Sandboxando o repo2'

So all we had to do was give the push:

git checkout master && git push -u origin master
git checkout develop && git push -u origin develop

The step of isolating the repositories in different folders was my strategy, because the focus of the initial repositories were distinct. One was Totalcross, the other GWT, and the third was the common dependency between the two.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.