3

I have separate GIT repositories for each Arduino Project I have developed which I handle using SourceTree connected to remote repositories in Bitbucket.

I would like to know how can I join these repositories into one and conserve the history changes of each file.

Is it possible to do it within SourceTree? I have not used GIT by command line yet.

Serge
  • 312
  • 5
  • 20

1 Answers1

0

You can create a new git repo in BitBucket, clone it and add your two existing bitbucket repos as submodules of this new repo.

With Sourcetree (since 2012 and its 1.3 version), it is easy.

https://blog.sourcetreeapp.com/files/2012/02/SourceTree_Submodules1.png

You’ll then be prompted to provide a source URL to clone the contents from, and the path within the current repository that this submodule will reside.

Once you have made changes in any of those submodules, you can push everything (the submodules, but also the parent repo which records gitlinks, special entries in the index)

http://blog.sourcetreeapp.com/files/2012/02/SourceTree_Submodules5.png

(this screenshot is for a mercurial repo, but would work the same for a git repo)


The other alternative is git subtree, illustrated here, which differs from submodule.

Even though the git-subtree.sh add --prefix /url/to/repo.git master --squash will records a merge commit by squashing the whole history of the vim-surround repository into a single one, a subtree push would still push bash additional history to your original subtree repo, preserving and completing its history.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I have tried your suggestion, however I dont know if it is what I am looking for. I have created a different folder and repository for each of my arduino/electronic projects. Now I find that I have too many projects and its a pain to have to create an individual repository for each new project so would like to join them all to a new repository call "electronic projects". Any suggestion? – Serge Oct 16 '15 at 06:04
  • @Serge Then you can look into git substree (https://developer.atlassian.com/blog/2015/05/the-power-of-git-subtree), that I illustrated in http://stackoverflow.com/a/24709789/6309. It differs from submodule (http://stackoverflow.com/a/31770147/6309) – VonC Oct 16 '15 at 06:10
  • I have tried subtree and indeed this is what I need. I managed to do pull old repositories into new repository but cant get it to keep the history once "imported" in the NEW repository. The OLD repository files are pulled, and added to the NEW repository but the commit history is lost. Any idea? The strange thing, in sourcetree the timeline shows the correct commit history, but in bitbucket the files only show one commit history. – Serge Oct 17 '15 at 22:25
  • @Serge but in bitbucket the files only show one commit history: http://blogs.atlassian.com/2013/05/alternatives-to-git-submodule-git-subtree/ if you have use --squash, that sounds logical. BitBucket will still refer to the remote subtree url repo, but your own repo sees only a merged commit squashing the history. – VonC Oct 18 '15 at 04:50
  • @Serge nevertheless, a subtree push would still push bash additional history to your original subtree repo, preserving and completing its history. I have edited the answer in that sense. – VonC Oct 18 '15 at 04:51
  • I did not check the "squash commits". I am not sure why the history was not preserved. What I did: 1) create a subtree pointing to old repository and to the folder inside the new repository 2) pull the subtree (which normally gave some kind of conflict but files were pulled (not in the indicated folder though) 3) commit the files. I also tried to 3) relocate the files and then commit but same problem – Serge Oct 18 '15 at 07:26
  • @Serge OK, can you try, for testing, to follow http://blogs.atlassian.com/2013/05/alternatives-to-git-submodule-git-subtree/ and https://developer.atlassian.com/blog/2015/05/the-power-of-git-subtree? – VonC Oct 18 '15 at 07:52