Class: Git::Commands::Checkout::Branch Private

Inherits:
Base
  • Object
show all
Defined in:
lib/git/commands/checkout/branch.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-checkout/2.53.0

Implements the git checkout command for switching branches

This command switches branches by updating the index and working tree to match the specified branch, and updating HEAD to point to that branch. It can also create new branches with the -b or -B options.

Examples:

Typical usage

checkout = Git::Commands::Checkout::Branch.new(execution_context)
checkout.call('main')
checkout.call(b: 'feature-branch')
checkout.call('origin/main', b: 'feature-branch', track: true)
checkout.call('abc123', detach: true)
checkout.call('main', force: 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(branch = nil, **options) ⇒ Git::CommandLineResult

Execute the git checkout command for branch switching

Parameters:

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

    the branch name, commit SHA, or ref to check out; when used with branch creation options (:b, :B, :orphan) this becomes the start point

  • options (Hash)

    command options

Options Hash (**options):

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

    suppress feedback messages

    Alias: :q

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

    force progress reporting even when not attached to a terminal (--progress)

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

    disable progress reporting even when attached to a terminal (--no-progress)

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

    proceed even if the index or working tree differs from HEAD; discards local changes and untracked files that are in the way

    Alias: :f

  • :b (String) — default: nil

    create a new branch with this name and switch to it; the positional branch argument becomes the start point

  • :B (String) — default: nil

    like :b, but reset the branch to the start point if it already exists

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

    set up upstream tracking configuration; true emits --track, 'direct' emits --track=direct, 'inherit' emits --track=inherit (--track)

    Alias: :t

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

    do not set up branch tracking even if branch.autoSetupMerge is configured (--no-track)

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

    automatically create and check out a local branch from a uniquely matching remote-tracking branch (--guess)

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

    disable automatic remote branch matching (--no-guess)

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

    create the new branch's reflog

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

    detach HEAD at the specified commit rather than pointing a branch at it

    Alias: :d

  • :orphan (String) — default: nil

    create a new unborn branch with no history; the positional branch argument becomes the start point

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

    perform a three-way merge when local modifications conflict with the target branch

    Alias: :m

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

    check out the branch even if it is already in use by another worktree

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

    silently overwrite ignored files when switching branches (--overwrite-ignore)

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

    abort the checkout if ignored files would be overwritten (--no-overwrite-ignore)

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

    update all active submodule working trees to match the new branch (--recurse-submodules)

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

    do not update submodule working trees when switching branches (--no-recurse-submodules)

  • :chdir (String) — default: nil

    change to this directory before running git; not passed to the git CLI

Returns:

Raises:

  • (ArgumentError)

    if unsupported options are provided

  • (Git::FailedError)

    if git exits with a non-zero exit status



# File 'lib/git/commands/checkout/branch.rb', line 56