Is it possible to have 2 local folders, each containing a different branch of the same repository?

thinsoldier
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 23, 2013

http://i.imgur.com/bn8xuw2.png

I have 2 branches of a project (A & B). I want to show the client 2 directions we could take the project in. I seem to only be able to switch the 1 project folder between the branches.

What I need is the ability to have a 2nd, completely different folder contain branch B.

1 folder for branch A - 1 folder for branch B.

That way I can show 1 thing on branch A then show the equivalent thing on branch B and have them side by side. With the current 1 folder - either A-mode or B-mode - I can't achieve this.

I don't want to switch branches within the existing folder. I want to keep branch A in the A folder then check out branch B into the B folder.

Is this possible?

2 answers

1 accepted

4 votes
Answer accepted
KieranA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 23, 2013

Hi Maurice,

Sure, we do this all the time. For SourceTree I run two branches, one for the default branch (most recent changes) and one for specific versions such as 1.5.8.

All you have to do is checkout your repository twice (or copy one folder). So in my file system I have two folders in the same directory, one called "SourceTree" and the other "SourceTreeDefault" each of which has SourceTree checked out into them. This way, I can run two instances of the same application at the same time if I want to. In each folder I have a different branch checked out. Remember that checking out a branch has nothing really to do with the remote, it's to do with your local working copy and what you've chosen to checkout.

Remember that anything which is committed and pushed in one of the repo's will be pullable in the other anyway, so they can stay in sync.

If I were you, I'd just checkout your remote to another folder in the same parent directory as your existing repository (with a different repo/folder name), then just run both projects by whatever means you're displaying them. If it's a web server you can specify a port to run them on, and if it's an application then two instances would run anyway.

Hope that helps.

thinsoldier
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 23, 2013

Thanks Keiran

If I were you, I'd just checkout your remote to another folder in the same parent directory as your existing repository (with a different repo/folder name)

I eventually realized I could do this. I was hoping there was a way to just duplicate the existing working copy folder without needing to download the files from the remote origin again.

http://i.imgur.com/cV9aBOj.png

Does this look like what you've described or is there some other way that doesn't involving having to download everything all over again?

Like abhishek_madhu likes this
0 votes
Shreyas Belle October 12, 2018

I know this is an old question but there is a better way to do this now. See this link. It describes briefly how to use "git worktree". AFAIK Sourtree doesn't have any support for worktrees yet.

martin.bjorcke December 19, 2018

The original context is about a temporary demo. To me the obvious simple solution is to copy the working folder in file explorer and then in Sourcetree switch the working folder to the other branch. Discard the copy after demo.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events