The [switch] Command

Switch worktree to another branch

Usage

libra switch [OPTIONS] [BRANCH]

Arguments

  • [BRANCH] - Branch name or commit hash

Description

Switch to a specified branch. The working tree and the index are updated to match the branch. You should make sure the working tree is clean before switching branches. Otherwise, the operation will be aborted.

Handle with remote branches

If you want to switch to a remote branch, you need to create a new branch based on the remote branch and switch to it.

libra fetch origin
libra branch -r # see a new branch named origin/new-branch
libra branch new-branch origin/new-branch
libra switch new-branch

Options

  • -c, --create <CREATE> Create a new branch based on the given branch or current HEAD, and switch to it.

  • -d, --detach Switch to a commit.

Note:

The options of the switch command are same as git, but the behavior is different.

  1. Git has a feature that, when you switch to a branch didn't exist locally but exists remotely, it will create a new branch locally and track the remote branch. Libra doesn't support this feature yet.

  2. Git didn't require a clean index and working tree before switching branches, but libra does.

Refs https://git-scm.com/docs/git-switch for more information.