Reputation: 61
so I have a commit hash from earlier in a project. How can I create a new worktree and have it's branch start from this specific commit?
Upvotes: 3
Views: 3562
Reputation: 488453
Use the command described in the git worktree
documentation:
git worktree add [--detach] [-b <new-branch>] <path> [<commit-ish>]
which in this case might be, e.g.:
$ cd gitrepo
$ git worktree add -b workbranch ../gitrepo.workbranch d16c37964
Preparing ../gitrepo.workbranch (identifier gitrepo.workbranch)
HEAD is now at d16c37964 Merge branch 'jk/attributes-path-doc'
after which:
$ cd ../gitrepo.workbranch
$ git status
On branch workbranch
nothing to commit, working tree clean
$ git rev-parse HEAD
d16c37964c284fa599251caafb51128c0df925a9
Upvotes: 7
Reputation: 94512
Create the branch before worktree:
git branch newbranch $SHA1
git worktree add /path/to/wt newbranch
Upvotes: 3