You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When creating a new worktree and entering its path (i.e. ~/path/to/worktree or ../worktree-name), those path segments (~, ..) do not expand because they are normally expanded automatically by the terminal (afaik) and instead a directory at /path/to/repository/~/path/to/worktree is created.
To Reproduce
Steps to reproduce the behavior:
Open a repository by running "lazygit" when pwd is a git repository
Activate Worktrees tab by typing 2 then ]
Choose "New worktree" by typing n
Choose "Create worktree from ref"
Choose a base ref (I recommend using your current checked out ref)
Enter a worktree path that begins with ".." or "~", and submit
Enter a new branch name (I recommend test/worktree-creation)
Take note of the new Worktree -> Path relative to the Worktree -> Path when using the arrow key select your previous checked-out worktree
Expected behavior
A clear and concise description of what you expected to happen.
I expect ".." and "~" to expand as they would if I ran the command in my terminal directly, and the worktree to be created accordingly
Screenshots
If applicable, add screenshots to help explain your problem.
Version info: Run lazygit --version and paste the result here
commit=, build date=, build source=Homebrew, version=0.53.0, os=darwin, arch=arm64, git version=2.39.5 (Apple Git-154) Run git --version and paste the result here
git version 2.39.5 (Apple Git-154)
Additional context
Add any other context about the problem here.
None to share
Note: please try updating to the latest version or manually building the latest master to see if the issue still occurs.
I was able to reproduce this on WSL with ~ at the start of the path, but unable to reproduce when using .. at the start of the path. That worked perfectly fine for me and produced the expected output.
We don't do anything weird with the Path argument:
So it seems the problem comes down to the way that Go's os/exec behaves:
Unlike the "system" library call from C and other languages, the os/exec package intentionally does not invoke the system shell and does not expand any glob patterns or handle other expansions, pipelines, or redirections typically done by shells. The package behaves more like C's "exec" family of functions.
We could add a patch similar to the following to make ~ in particular work. Not sure if that's too hacky or not. There seems to have once been a pretty popular repo that did much of the same (until it was archived and os.UserHomeDir was created, which took away much of its core functionality) https://github.com/mitchellh/go-homedir/tree/main
So the "problem" is that os.exec does not do the shell interpolation of ~ like the reporter expects. (I concede that it might not be considered a "problem" since this is intended behavior)
@ChrisMcD1 You are right. For some reason I was thinking this os/exec comment would only apply to the executable being called, but of course it applies to command arguments in the same way.
Activity
ChrisMcD1 commentedon Aug 12, 2025
I was able to reproduce this on WSL with
~at the start of the path, but unable to reproduce when using..at the start of the path. That worked perfectly fine for me and produced the expected output.We don't do anything weird with the
Pathargument:lazygit/pkg/gui/controllers/helpers/worktree_helper.go
Line 117 in b1382da
lazygit/pkg/commands/git_commands/worktree.go
Line 40 in b1382da
So it seems the problem comes down to the way that Go's
os/execbehaves:https://pkg.go.dev/os/exec
We could add a patch similar to the following to make
~in particular work. Not sure if that's too hacky or not. There seems to have once been a pretty popular repo that did much of the same (until it was archived andos.UserHomeDirwas created, which took away much of its core functionality) https://github.com/mitchellh/go-homedir/tree/mainstefanhaller commentedon Aug 12, 2025
This has nothing to do with os/exec, which is not involved here.
The patch seems reasonable to me, except that I would extract the logic to a helper function (maybe somewhere in
pkg/utils/).ChrisMcD1 commentedon Aug 13, 2025
I might be reading this wrong, but as I see it, the opts.Path goes here
lazygit/pkg/commands/git_commands/worktree.go
Lines 37 to 42 in b1382da
which then goes to here
lazygit/pkg/commands/oscommands/cmd_obj_builder.go
Lines 31 to 32 in b1382da
which then is calling
os.exechere:lazygit/pkg/commands/oscommands/cmd_obj_builder.go
Lines 37 to 38 in b1382da
So the "problem" is that
os.execdoes not do the shell interpolation of~like the reporter expects. (I concede that it might not be considered a "problem" since this is intended behavior)stefanhaller commentedon Aug 13, 2025
@ChrisMcD1 You are right. For some reason I was thinking this os/exec comment would only apply to the executable being called, but of course it applies to command arguments in the same way.
stefanhaller commentedon Jun 30, 2026
This is included in #5741, along with a lot of other improvements to the whole create worktree flow.
iLynxcat commentedon Jun 30, 2026
yay! cheers for resolving this, glad to see it -- and still happily using lazygit every day :)
Make creating worktrees simpler and less error-prone (jesseduffield#5741