Tutorial - arxanas/git-branchless GitHub Wiki

Introduction

The following document contains a brief overview of some of the common commands. See also this user-contributed tutorial for a more guided introduction, or check the Workflows in the sidebar.

Demo

If you prefer an animated introduction, you can watch this screencast for a quick overview of some of the commands:

Demo of git-branchless

Inspecting state

The most common command you'll run is git sl (short for git smartlog). This renders a display of commits you're working on.

Moving between commits

If you want to check out a branch, use git checkout <branch>. If you want to move to a specific commit you're working on, copy the commit hash from git sl, and then run git checkout <hash>.

For convenience, to move between commits in a stack of commits, you can use git next and git prev:

  • git next: move to the this commit's child.
  • git next <N>: move to this commit's Nth descendant commit.
  • git prev: move to this commit's parent.
  • git prev <N>: move to this commit's Nth ancestor commit.

Hiding and showing commits

If you want to hide a commit from the smartlog, use git hide <hash> to hide it. Note that this makes the commit eligible for garbage collection later, so don't hide it unless you're okay with it being permanently deleted in the future.

If you want to unhide a commit that you previously hid, use git unhide <hash> (assuming that it hasn't been garbage collected yet).

You can also use git undo to undo a mistaken hide operation (see below).

Changing commits

To change a commit, you can check out to the commit and run git amend. Sometimes, this will suggest that you run git restack to update descendant commits. If prompted, do so.

You can move a commit or sequence of commits from one location to another using git rebase.

You can delete, reorder, and combine commits using git rebase -i. This is an important part of the branchless workflow, so you should familiarize yourself with it. See https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History for more details.

If you ever make a mistake, just run git undo to undo it (see below).

Undoing

NOTE: git undo only works properly with Git v2.29 or later. You can upgrade to Git v2.29 at any time, but you'll only be able to correctly undo operations that happened after the upgrade.

If you've done anything incorrectly (bad rebase; deleted a branch; resolved a merge conflict incorrectly), you can use git undo to go back to a previous state of the repository. The git undo command is interactive: you'll select a previous state of the repository by looking at the smartlog at that point in time, and then be able to revert to it.

You can even undo a git undo operation.

You should ensure that you don't have any uncommitted changes when you run git undo.

⚠️ **GitHub.com Fallback** ⚠️