Class: Git::Commands::Branch::Create Private

Inherits:
Git::Commands::Base show all
Defined in:
lib/git/commands/branch/create.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-branch/2.53.0

git branch command for creating new branches

This command creates a new branch head pointing to the current HEAD or a specified start point.

Examples:

Basic branch creation

create = Git::Commands::Branch::Create.new(execution_context)
create.call('feature-branch')

Create branch from a specific start point

create = Git::Commands::Branch::Create.new(execution_context)
create.call('feature-branch', 'main')

Force create (reset existing branch)

create = Git::Commands::Branch::Create.new(execution_context)
create.call('feature-branch', 'main', force: true)

Create with upstream tracking

create = Git::Commands::Branch::Create.new(execution_context)
create.call('feature-branch', 'origin/main', track: true)

Create without upstream tracking

create = Git::Commands::Branch::Create.new(execution_context)
create.call('feature-branch', 'origin/main', no_track: true)

Create with inherited tracking configuration

create = Git::Commands::Branch::Create.new(execution_context)
create.call('feature-branch', 'origin/main', track: 'inherit')

See Also:

Instance Method Summary collapse

Methods inherited from Git::Commands::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_name, **options) ⇒ Git::CommandLineResult #call(branch_name, start_point, **options) ⇒ Git::CommandLineResult

Overloads:

  • #call(branch_name, **options) ⇒ Git::CommandLineResult

    Create a new branch from the current HEAD

    Parameters:

    • branch_name (String)

      the name of the branch to create

    • options (Hash)

      command options

    Options Hash (**options):

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

      configure upstream tracking for the new branch

      • true: Set up tracking using the start-point branch itself (--track)
      • 'direct': Same as true, explicitly use start-point as upstream (--track=direct)
      • 'inherit': Copy upstream configuration from start-point branch (--track=inherit)

      Alias: :t

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

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

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

      reset the branch to start point even if it already exists

      Without this, git branch refuses to change an existing branch.

      Alias: :f

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

      create the branch in the superproject and all submodules

      This is an experimental feature.

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

      suppress informational messages

      Alias: :q

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

      create the branch's reflog (--create-reflog)

      Enables date-based sha1 expressions such as branch@{yesterday}. In non-bare repositories, reflogs are usually enabled by default via core.logAllRefUpdates.

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

      forcibly disable the branch's reflog (--no-create-reflog)

    Returns:

    Raises:

    • (ArgumentError)

      if unsupported options are provided

    • (Git::FailedError)

      if git exits with a non-zero exit status

  • #call(branch_name, start_point, **options) ⇒ Git::CommandLineResult

    Create a new branch from the specified start point

    Parameters:

    • branch_name (String)

      the name of the branch to create

    • start_point (String, nil)

      the commit, branch, or tag to start the new branch from

      Can also use <rev-A>...<rev-B> syntax for merge base.

    • options (Hash)

      command options

    Options Hash (**options):

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

      configure upstream tracking for the new branch

      • true: Set up tracking using the start-point branch itself (--track)
      • 'direct': Same as true, explicitly use start-point as upstream (--track=direct)
      • 'inherit': Copy upstream configuration from start-point branch (--track=inherit)

      Alias: :t

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

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

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

      reset the branch to start point even if it already exists

      Without this, git branch refuses to change an existing branch.

      Alias: :f

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

      create the branch in the superproject and all submodules

      This is an experimental feature.

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

      suppress informational messages

      Alias: :q

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

      create the branch's reflog (--create-reflog)

      Enables date-based sha1 expressions such as branch@{yesterday}. In non-bare repositories, reflogs are usually enabled by default via core.logAllRefUpdates.

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

      forcibly disable the branch's reflog (--no-create-reflog)

    Returns:

    Raises:

    • (ArgumentError)

      if unsupported options are provided

    • (Git::FailedError)

      if git exits with a non-zero exit status



# File 'lib/git/commands/branch/create.rb', line 58