In Mercurial when I have a repository checked-out in my local directory "C:\my-projects\my-old-hg-repo-checkout", with the "hg share" extension enabled, command hg share C:\my-projects\my-old-hg-repo-checkout C:\my-projects\my-new-hg-repo-checkout
will create a new local directory that "shares the same remote" (i.e if I pull remote changes in one directory, they are visible in the other).
How exactly can I do the same thing with my local check-out of a git directory, "C:\my-projects\my-old-git-repo-checkout", that I want to duplicate in "C:\my-projects\my-new-git-repo-checkout" (while ensuring they "share the same remote", i.e pulling remote changes from one directory will make them visible in the other)?
You want to use the git worktree
command to create additional worktrees for your local git repo:
git clone <url of remote repo>
cd <directory>
git worktree add <path-to-new-directory> <branch_name>
You now have two worktrees for your git repo, each in different directories. You can add as many worktrees you want with additional git worktree add
commands. Note that two worktrees cannot have the same branch checked out.
git fetch
updates the local repo from the remote, and as both worktrees are attached to the same local repo, you will have updated information in both worktrees.
See https://git-scm.com/docs/git-worktree for documentation on the git worktree
command.