Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Git - Support git worktrees in workspace #68038

Open
colemickens opened this issue Feb 7, 2019 · 20 comments
Open

Git - Support git worktrees in workspace #68038

colemickens opened this issue Feb 7, 2019 · 20 comments
Assignees
Labels
feature-request Request for new features or functionality git GIT issues help wanted Issues identified as good community contribution opportunities
Milestone

Comments

@colemickens
Copy link

$ mkdir repro
$ cd repro
$ mkdir example1
$ cd example1
$ git init; echo "hello" > world.txt; git add world.txt; git commit -m "init";
$ git worktree add ../example1branchA
$ git worktree add ../example1branchB
$ cd ..

$ mkdir example2
$ cd example2
$ git init; echo "hello" > world.txt; git add world.txt; git commit -m "init";
$ cd ..

Scenario:

  1. Open repro directory in VS Code
  2. Go to Git tab.

Expected: "Source Control Providers" lists Git repos.

  • example1
  • example1branchA
  • example1branchB
  • example2

Actual: "Source Control Providers" lists Git repos.

  • example1
  • example2

I sometimes will have lots of branches checked out in parallel on huge repos that I can't afford to clone multiple times. I would also like to be able to use VS Code's source control functionality with these checkouts all the same.

Thanks! and thanks for Code!

@vscodebot
Copy link

vscodebot bot commented Feb 7, 2019

(Experimental duplicate detection)
Thanks for submitting this issue. Please also check if it is already covered by an existing one, like:

@vscodebot vscodebot bot added the git GIT issues label Feb 7, 2019
@colemickens
Copy link
Author

Thank you honorable vscodebot, but this feature request is not a duplicate of that issue.

@joaomoreno joaomoreno added this to the Backlog milestone Feb 8, 2019
@joaomoreno joaomoreno added the feature-request Request for new features or functionality label Feb 8, 2019
@joaomoreno joaomoreno changed the title Source Control Providers does not discover git worktrees in workspace Git: Support git worktrees in workspace Feb 8, 2019
@joaomoreno joaomoreno added the help wanted Issues identified as good community contribution opportunities label Feb 8, 2019
@charltonstanley
Copy link

i just tested this out and it looks to be fixed now on v1.35.0 @colemickens is this still an issue for you?
image

@JojoS62
Copy link

JojoS62 commented Dec 9, 2019

In current version 1.40.2 I can see the multiple source control providers only when the root does not contain a .git and is initialized by the command 'Git: Initialize Repository'.
After closing and reopening VSCode, only the git for the project root is shown, subdirs with own .git are no longer listed.

@rajatvijay
Copy link

I am facing a similar issue, any updates here?

@rohit04saluja
Copy link

Is someone working on this? Need the worktree support

@lszomoru lszomoru self-assigned this Oct 4, 2021
@seyeeet
Copy link

seyeeet commented Oct 19, 2021

any update on this? how I can use worktree while using vscode?

@colemickens
Copy link
Author

I don't know why this keeps getting comments, afaict vs code supports work trees just fine these days.

@redeboer
Copy link

I don't know why this keeps getting comments, afaict vs code supports work trees just fine these days.

How can VSCode handle the scenario described above? For clarity, the issue is about git worktree, not comparing working trees etc.

I sometimes will have lots of branches checked out in parallel on huge repos that I can't afford to clone multiple times. I would also like to be able to use VS Code's source control functionality with these checkouts all the same.

I think the key point of this issue is this. I would also be interested in these kind of quickly cloned workspaces.

@halfdan
Copy link

halfdan commented Feb 15, 2022

What's missing here is the ability to switch between branches and/or create a new worktree when working in a bare repo. The branch listing works just fine but vscode doesn't automatically change the working directories when I select a branch that exists as a worktree.

@HybridEidolon
Copy link

The worktree support also doesn't work if the worktree is located in another path, e.g.:

Code/project/.git -- actual repo
Code/project -- primary 
Code/project2/.git -- worktree of Code/project

and opening project and project2 in separate VS Code workspaces, only project will see the repo, not project2.

@cgarrovillo
Copy link

cgarrovillo commented May 22, 2022

As an example, the Gitlens repo might be a good place to start as they have this included in their extension but behind a paywall.

I'm not sure how they are handling something like a node_modules folder, but maybe someone else who was willing to pay can have some input?

@jeffrey-aguilera
Copy link

I don't know why this keeps getting comments, afaict vs code supports work trees just fine these days.

Not with devcontainers.

@intrnl
Copy link

intrnl commented Jun 7, 2022

EDIT: I checked if I had the upstream set, which I didn't, whoops, but it seems that it's still the same result.

I have a setup where I have this folder with a bare-cloned repository and have worktrees for each branches I work on, for some reason it thinks all of my branches are unpublished, which it isn't the case.

.git          // gitdir: ./.bare
.bare/        // bare cloned repository
staging/
production/
development/
feature-xxx/ 
bugfix-xxx/

@afa7789
Copy link

afa7789 commented Jul 1, 2022

Yeah my DevContainner is not working with versioncontrol. ( Linux user )
image
image
After I got back to locally:
image

@afa7789
Copy link

afa7789 commented Jul 1, 2022

@joaomoreno , @lszomoru . I think that pasting the images in this issues is better then creating a new one.

@ghost
Copy link

ghost commented Jul 11, 2022

EDIT: I checked if I had the upstream set, which I didn't, whoops, but it seems that it's still the same result.

I have a setup where I have this folder with a bare-cloned repository and have worktrees for each branches I work on, for some reason it thinks all of my branches are unpublished, which it isn't the case.

.git          // gitdir: ./.bare
.bare/        // bare cloned repository
staging/
production/
development/
feature-xxx/ 
bugfix-xxx/

@intrnl Can you share what you did to verify and set upstream? I feel kinda dumb cause apparently what I've done just isn't correct. I've got a very similar structure and am seeing this same behavior.

@madorodam
Copy link

There are workarounds for the Dev Container issue, like:

  • create a workspace and save it in a folder that contains all git worktrees.
  • add the worktree git folder to the workspace.
  • create the devcontainer in the folder where the workspace was saved (the create devcontainer configuration action does this).
  • and in the git worktree folder edit the .git file and replace the gitdir with a relative folder instead of an absolute one (this is the main trick in fact, the other are only docker mount tricks).

Alternatively I think it might work also to add/mount the main git for the worktrees, in the same relative position, using a docker-compose.yaml file and consume it in devcontrainer config. Did not test this myself yet.

@well1791
Copy link

well1791 commented Sep 4, 2023

I have an alternative solution that goes like this:

  1. clone a bare repo git clone --single-branch --bare "$repo"
  2. enter the clone and add remote branches
    git config --local --add remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
  3. create 2 worktrees inside
    git worktree add -b rename1 wt/1/$proj_name
    git worktree add -b rename1 wt/1/$proj_name
  4. enter the first worktree cd wt/1/$proj_name

here's my fish script for reference

# file: ~/.config/fish/functions/gcb.fish
function gcb --description 'Clones a repo as bare and set up two worktrees.'
    set repo "$argv[1]"
    set dir "$argv[2]"

    if test -z $dir
        set dir (echo "$repo" | grep -o '[^/]*$')
    end

    set proj_name (string join . (string split . "$dir")[1..-2])

    git clone --single-branch --bare "$repo" "$dir"

    cd "$dir"

    git fetch --all --prune
    git config --local --add remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
    git worktree add -b rename1 wt/1/$proj_name
    git worktree add -b rename2 wt/2/$proj_name

    cd wt/1/$proj_name
end

In the end I would do something like

gcb git@github.com:microsoft/vscode.git && code .

Hope it helps.

@moatorres
Copy link

I'm having a similar issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for new features or functionality git GIT issues help wanted Issues identified as good community contribution opportunities
Projects
None yet
Development

Successfully merging a pull request may close this issue.