Module: Git::Commands::Checkout Private

Defined in:
lib/git/commands/checkout.rb,
lib/git/commands/checkout/files.rb,
lib/git/commands/checkout/branch.rb

Overview

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

Commands for switching branches and restoring files via git checkout

This module contains command classes split by checkout mode:

  • Branch — switch branches or create and switch to a new branch
  • Files — restore working tree files from a given tree-ish

Examples:

Switch to an existing branch

cmd = Git::Commands::Checkout::Branch.new(lib)
cmd.call('main')

Create and switch to a new branch

cmd = Git::Commands::Checkout::Branch.new(lib)
cmd.call('main', b: 'feature/new-feature')

Restore a file from the index (discard uncommitted changes)

cmd = Git::Commands::Checkout::Files.new(lib)
cmd.call(pathspec: ['lib/my_file.rb'])

Restore a file from a specific branch

cmd = Git::Commands::Checkout::Files.new(lib)
cmd.call('main', pathspec: ['lib/my_file.rb'])

See Also:

Defined Under Namespace

Classes: Branch, Files