Skip to content

Instantly share code, notes, and snippets.

@nadyshalaby
Last active May 26, 2022 14:25
Show Gist options
  • Save nadyshalaby/05e2d18c726cb7fd1043fa6dbb10c5d2 to your computer and use it in GitHub Desktop.
Save nadyshalaby/05e2d18c726cb7fd1043fa6dbb10c5d2 to your computer and use it in GitHub Desktop.
Git Worktree Most Used Command

Worktree most used commands

To open worktree from current bransh

git worktree add --detach <worktree-path> <branch-name>

To open worktree from remote branch

git worktree add --detach <worktree-path> <remote-name>/<branch-name>

To open worktree from commit

git worktree add --detach <worktree-path> <commit-id>

To add worktree branch from local branch

git worktree add -b <new-branch-name> <worktree-path> <source-branch-name>

To add worktree branch from remote branch

git worktree add -b <new-branch-name> <worktree-path> <remote-name>/<source-branch-name>

To add worktree branch from commit

git worktree add -b <new-branch-name> <worktree-path> <commit-id>

To remove worktree

git worktree remove <worktree-path>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment