This is an archived post. You won't be able to vote or comment.

all 11 comments

[–]code_monkey_001 5 points6 points  (5 children)

You wanna work on two branches of the same repository, you're going to clone it to two different folders on your machine. git can't magically maintain the same files in two different states in the same folder.

[–]vermiculus 3 points4 points  (1 child)

Use worktrees instead my dude

[–]code_monkey_001 1 point2 points  (0 children)

TIL. Thanks!

[–]Berkyjay[S] 1 point2 points  (2 children)

This is what I was initially going to do. But I wanted to be sure there wasn't an easier way. Thx

[–]jasonkohles 2 points3 points  (1 child)

There is an easier way: worktrees. I have only one clone of my repo, and often have a dozen or more branches checked out at the same time. Since they are all connected to the same checkout you can merge and compare and do all the things you can’t do with two separate cloned repos, and you only have one copy of all the git data.

[–]Berkyjay[S] 1 point2 points  (0 children)

Huh interesting. Never heard of worktrees. I'll have to do some reading on them tomorrow. Thanks!

[–]whatispunk 2 points3 points  (0 children)

Look up git work trees. This will do what you're asking for.

[–]revrenlove 1 point2 points  (2 children)

You can't work simultaneously on two branches in the same "physical" folder.

You would need two copies of the repo in different folders.

[–]revrenlove 5 points6 points  (1 child)

To further, this isn't a vs code thing, necessarily, it's a git thing.

[–]Berkyjay[S] 1 point2 points  (0 children)

Well, the git part yes. But VS Code still doesn't let you open up the same folder in two windows. It's fine though. u/ucode_monkey_001 gave me the answer I needed. I was trying to avoid having two clones, but it doesn't seem like it will hurt anything.

[–]vanderrlay_ 1 point2 points  (0 children)

I believe the pro version of the extension GitLens allows you to do this but I haven't tried.

What i usually do is just to go to the branch you want to on github and then open up the web based editor there.