3

On Bitbucket I have multiple repositories, one of them is a general one (like a library)

I have multiple projects that are using this same repository. For the moment each project have different sourcetree repository linked to the same repository on Bitbucket and I would like to know if it's possible to make only one sourcetree repository for multiple different location on my computer.

For example :

I have 3 projects call them A, B & C
On Bitbucket I have 5 repositories call them (AA, BB, CC, DD, General)
What I have is
Project A need AA, BB & General
Project B need CC & General
Project C need DD & General

I would like to know if in sourcetree I can make only 1 repository that is linked to the 3 projects in 3 different places or if only can use one location and I have to make 3 sourcetree repositories for each projects.

Thanks for your answers.

user3718160
  • 481
  • 2
  • 11
  • 23

1 Answers1

4

... one sourcetree repository for multiple different location on my computer.

Yes you can.

You will have to use git v2.5 and above and then you can use the git worktree.

Git worktree was introduced in 2007 under the contrib folder in git repo and was called new-workdir.


git worktree

for example:

git worktree add <second path>

will create another folder on your computer which allow you to work on different branch simultaneously.

git worktree will create 2 separate working folders separated from each other while pointing to the same repository.

This will allow you do to any experimentals on the new worktree without having any effect on the repository itself. In the attached image you can see that there are 2 separate working folder but both of them are using a single repo and share the content.

Here is a sample on how to create new worktree and what is the result of it:

enter image description here

CodeWizard
  • 128,036
  • 21
  • 144
  • 167
  • 1
    this is to work on 2 different version of the same code right ? What I want is a unique repository to be the exact same one on the 3 differents project and if I make a change in one of them then the 2 other also have the change without having to push it on remote and then pull it back on the 2 other projects – user3718160 Jun 22 '16 at 13:31
  • So checkout the branch 3 times under a different name. you can use `git cherry-pick` to add any desired commit to any given bramch > What I want is a unique repository to be the exact same one on the 3 differents project and if I make a change in one of them then the 2 other also have the change without having to push it on remote and then pull it back on the 2 other projects This is EXACTLY what worktree is for, its a shared repository where you can work on a multiple branches and share the data between the multiple instances – CodeWizard Apr 07 '17 at 15:11
  • I think OP is talking about Bitbucket "Projects", though – endolith Jun 22 '20 at 15:36