# `Git.Commands.Switch`
[🔗](https://github.com/joshrotenberg/git_wrapper_ex/blob/main/lib/git/commands/switch.ex#L1)

Implements the `Git.Command` behaviour for `git switch`.

`git switch` is the modern (Git 2.23+) command for switching branches,
replacing the branch-switching role of `git checkout`. It is more focused
and less error-prone than `checkout` for branch operations.

# `t`

```elixir
@type t() :: %Git.Commands.Switch{
  branch: String.t() | nil,
  create: boolean(),
  detach: boolean(),
  discard_changes: boolean(),
  force: boolean(),
  force_create: boolean(),
  guess: boolean() | nil,
  merge: boolean(),
  orphan: boolean(),
  track: String.t() | nil
}
```

# `args`

```elixir
@spec args(t()) :: [String.t()]
```

Returns the argument list for `git switch`.

## Examples

    iex> Git.Commands.Switch.args(%Git.Commands.Switch{branch: "main"})
    ["switch", "main"]

    iex> Git.Commands.Switch.args(%Git.Commands.Switch{branch: "feat/new", create: true})
    ["switch", "-c", "feat/new"]

    iex> Git.Commands.Switch.args(%Git.Commands.Switch{branch: "abc123", detach: true})
    ["switch", "--detach", "abc123"]

# `parse_output`

```elixir
@spec parse_output(String.t(), non_neg_integer()) ::
  {:ok, Git.Checkout.t()}
  | {:ok, :done}
  | {:error, {String.t(), non_neg_integer()}}
```

Parses the output of `git switch`.

Reuses `Git.Checkout` parsing since the output format is the same
(e.g. "Switched to branch 'main'").

---

*Consult [api-reference.md](api-reference.md) for complete listing*
