Class: Git::Commands::Worktree::Add Private

Inherits:
ManagementBase show all
Defined in:
lib/git/commands/worktree/add.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Note:

arguments block audited against https://git-scm.com/docs/git-worktree/2.54.0

Creates a new linked worktree

Examples:

Add a worktree at a path (auto-creates a branch)

Git::Commands::Worktree::Add.new(execution_context).call('/tmp/feature')

Add a worktree and check out an existing branch

Git::Commands::Worktree::Add.new(execution_context).call('/tmp/hotfix', 'main')

Add a worktree with a new branch

Git::Commands::Worktree::Add.new(execution_context).call('/tmp/feat', b: 'feature/new')

Add a detached-HEAD worktree locked at creation

Git::Commands::Worktree::Add.new(execution_context).call('/tmp/exp', detach: true, lock: true)

See Also:

Instance Method Summary collapse

Methods inherited from Base

allow_exit_status, arguments, #initialize, requires_git_version, skip_version_validation

Constructor Details

This class inherits a constructor from Git::Commands::Base

Instance Method Details

#call(path, commit_ish = nil, **options) ⇒ Git::CommandLineResult

Create a new linked worktree and check out commit_ish into it

Parameters:

  • path (String)

    filesystem path for the new worktree

  • commit_ish (String, nil) (defaults to: nil)

    (nil) branch, tag, or commit to check out

    When omitted, git creates a new branch named after the final path component and checks it out.

  • options (Hash)

    command options

Options Hash (**options):

  • :force (Boolean, Integer, nil) — default: nil

    override safety guards

    Pass true or 1 to emit --force once. Pass 2 to emit --force --force, which also allows adding worktrees for locked branches.

    Alias: :f

  • :b (String) — default: nil

    create a new branch with this name and check it out

  • :B (String) — default: nil

    create or reset a branch with this name and check it out

  • :detach (Boolean, nil) — default: nil

    check out in detached-HEAD state

    Alias: :d

  • :checkout (Boolean, nil) — default: nil

    control whether the working tree is checked out after creation (--checkout)

  • :no_checkout (Boolean, nil) — default: nil

    suppress the initial checkout after worktree creation (--no-checkout)

  • :guess_remote (Boolean, nil) — default: nil

    base new branch on a matching remote-tracking branch (--guess-remote)

    Applied when no commit_ish argument is provided.

  • :no_guess_remote (Boolean, nil) — default: nil

    disable guess-remote behavior (--no-guess-remote)

  • :relative_paths (Boolean, nil) — default: nil

    link worktrees using relative paths (--relative-paths)

    Overrides the worktree.useRelativePaths config option.

  • :no_relative_paths (Boolean, nil) — default: nil

    use absolute paths for worktree links (--no-relative-paths)

    Overrides the worktree.useRelativePaths config option.

  • :track (Boolean, nil) — default: nil

    mark the upstream branch for tracking (--track)

  • :no_track (Boolean, nil) — default: nil

    do not mark the upstream branch for tracking (--no-track)

  • :lock (Boolean, nil) — default: nil

    lock the worktree immediately after creation

  • :orphan (Boolean, nil) — default: nil

    create an empty worktree associated with a new unborn branch

  • :quiet (Boolean, nil) — default: nil

    suppress informational messages

    Alias: :q

  • :reason (String) — default: nil

    explanation for why the worktree is locked

    Only meaningful when used with :lock.

Returns:

Raises:

  • (ArgumentError)

    if unsupported options are provided

  • (Git::FailedError)

    if git exits with a non-zero exit status



# File 'lib/git/commands/worktree/add.rb', line 52