Logo

dev-resources.site

for different kinds of informations.

Pick Files from a List for Git Add and Stash Directly in Your Terminal

Published at
1/11/2025
Categories
git
shell
tooling
opensource
Author
Takuto Yuki
Categories
4 categories in total
git
open
shell
open
tooling
open
opensource
open
Pick Files from a List for Git Add and Stash Directly in Your Terminal

Introduction

As developers, we often find ourselves working with Git in the terminal. While tools like VSCode or GUI-based Git clients offer file selection features, many developers prefer the simplicity and speed of the terminal.

Git also provides a built-in interactive mode with git add -i. Have you ever tried using it? Personally, I didn’t find it particularly user-friendly.

There are powerful tools like fzf that enhance terminal interactivity, but sometimes you just don't need all those advanced features. For me, having a lightweight tool to interactively select files for git add and git stash felt like the perfect solution.

When selection isn't possible, the typical workflow often involves running git status, copying file names, and pasting them repeatedly for git add or git stash. This copy-paste process can be tedious and error-prone, especially in larger repositories.

To address this need, I wrote approximately 150 lines of code to create git-select-list, a simple yet effective tool for developers seeking interactivity without complexity. You can find the repository here: git-select-list.

Image git-select-list

Features

  • Interactive UI: Navigate with arrow keys, select with a, and toggle all with u.
  • Multiple Actions: Supports git add, git stash, git stash apply, and git stash drop.
  • Lightweight Setup: No external dependencies, with an included setup script.

Setup

1. Clone the repository

   git clone https://github.com/pppp606/git-select-list.git
   cd git-select-list

2. Run the setup script

   bash setup.sh

3. After setup, you can use the git sl command.

The setup script configures a convenient alias using Git's built-in alias feature:

   git config --global alias.sl '!sh $(pwd)/scripts/git-select-list.sh'

This alias allows you to execute the tool directly as git sl, making it feel like a native Git command. If you haven’t explored Git’s alias functionality before, it’s a simple and powerful way to extend Git’s behavior without modifying your workflow.

Usage

Command Format

git sl <action> [subaction]

Supported Actions and Subactions

Command Description
git sl add Interactively select modified files to stage.
git sl stash Interactively select modified files to stash.
git sl stash apply Interactively select stashes to apply.
git sl stash drop Interactively select stashes to drop.

Key Bindings

  • Arrow Keys: Navigate between items.
  • a Key: Select or deselect the current item.
  • u Key: Select or deselect all items.
  • Enter Key: Confirm the selection.
  • ESC Key: Exit without making any changes.

Thanks for Checking It Out!

If you find git-select-list useful, feel free to use it in your projects. And if you like it, consider starring the repository on GitHub—it would make my day!

Git Select List

git-select-list is a tool to interactively perform Git operations. It allows you to select files or stashes from a list for actions like git add, git stash, git stash apply, and git stash drop.

2025-01-11_20.29.54.mov

Features

  • Interactive UI: Navigate with arrow keys, select with a, and toggle all with u.
  • Multiple Actions: Supports git add, git stash, git stash apply, and git stash drop.
  • Lightweight Setup: No external dependencies, with an included setup script.

Setup

Steps

  1. Clone this repository:

    git clone https://github.com/pppp606/git-select-list.git
    cd git-select-list
  2. Run the setup script:

    bash setup.sh
  3. After setup, you can use the git sl command.

Usage

Command Format

git sl <action> [subaction]

Supported Actions and Subactions





















Command Description
git sl add Interactively select modified files to stage.
git sl stash Interactively select modified files to stash.
git sl
…





Featured ones: