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
pppp606
Categories
4 categories in total
git
open
shell
open
tooling
open
opensource
open
Author
7 person written this
pppp606
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
Enter fullscreen mode Exit fullscreen mode

2. Run the setup script

   bash setup.sh
Enter fullscreen mode Exit fullscreen mode

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'
Enter fullscreen mode Exit fullscreen mode

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]
Enter fullscreen mode Exit fullscreen mode

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
    Enter fullscreen mode Exit fullscreen mode
  2. Run the setup script:

    bash setup.sh
    Enter fullscreen mode Exit fullscreen mode
  3. After setup, you can use the git sl command.


Usage

Command Format

git sl <action> [subaction]
Enter fullscreen mode Exit fullscreen mode

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
…





shell Article's
30 articles in total
Favicon
Poor man's parallel in Bash
Favicon
Ergonomic Pyhon Text Piping Solution for Linux Shell with pypyp and uv
Favicon
Become a Bash Scripting Pro in 10 Minutes: A Quick Guide for Beginners
Favicon
Final Bash Script Series Mastering Remote Server Management and Web App Deployment
Favicon
kkTerminal —— A terminal for Web SSH connection
Favicon
The Complete Guide to Bash Commands
Favicon
Navigating TC39 Proposals: From Error Handling to Iterator.range
Favicon
Introducing TheShell: A Game-Changer in LivinGrimoire
Favicon
Pick Files from a List for Git Add and Stash Directly in Your Terminal
Favicon
Start Shell Programming: A Beginner's Guide âš™ [Part-I]
Favicon
Pytest Fish shell autocompletion
Favicon
Discover File Splitter & Merger: A Revolutionary Tool for Managing Large Files
Favicon
🚀 RazzShell v1.0.1 is Here: Plugin Support, Enhanced Job Management, and More! 🌟
Favicon
ps, kill -9 PID
Favicon
\\wsl$
Favicon
Escape quotes correctly when using psql via docker in bash
Favicon
Bash vs. Shell: The Ultimate Comparison
Favicon
Search and Sync Your Shell History With Atuin
Favicon
Building a (somewhat) intelligent agent
Favicon
Environment Management in Bash: Unlocking the Secrets of the Shell
Favicon
3 Must-Know File Permissions and Ownership Commands
Favicon
Ask Git to Show a Method
Favicon
UNIX
Favicon
DEV OPS JOURNEY
Favicon
Unlock the Secrets of Your Command Line with the History Command
Favicon
Mastering Text Processing with Grep, Sed, Awk, Cut, and Sort
Favicon
Shell Special Variables and Execution Environment
Favicon
Spice up Your Terminal With a Todo Reminder Using Starship Prompt and iZiDo Bash Script
Favicon
Introducing RazzShell: A Customizable Unix Shell for Modern CLI Users
Favicon
File Management in Bash : Commands and Examples

Featured ones: