GitHub - fossilet/git-add-new: A Git plugin that stages new files as pure additions · GitHub
Skip to content

About

A Git plugin that stages new files as pure additions

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

6 Commits

Folders and files

Repository files navigation

git-add-new

A Git plugin that stages new files as pure additions, making them appear as all green lines (additions) in VS Code and other diff viewers instead of showing as modified files.

What it does

When you add a new file to Git normally, diff viewers often show it as "modified" or may not highlight every line as an addition. This plugin uses the "empty file trick" to ensure new files appear as pure additions:

  1. Temporarily moves your file to a backup
  2. Creates an empty file with the same name
  3. Stages the empty file (git add)
  4. Restores your real file content (now showing as unstaged modifications)

The result: The staged version is empty, and your real content shows as unstaged additions (all green lines).

Important: This utility only operates on untracked files. It will never stage already-tracked files to preserve the "pure addition" behavior. Use regular git add for tracked files.

Requirements

  • Git
  • Bash 4.0 or newer

Installation

Clone the repository and put the script somewhere on your PATH. Git automatically resolves git add-new to the git-add-new executable.

git clone https://github.com/fossilet/git-add-new.git
cd git-add-new
mkdir -p ~/.local/bin
cp git-add-new ~/.local/bin/

Make sure ~/.local/bin is on your PATH:

export PATH="$HOME/.local/bin:$PATH"

Alternatively, symlink it so updates follow the clone:

ln -s "$PWD/git-add-new" ~/.local/bin/git-add-new

Verify the installation:

git add-new -h

Once installed, the plugin works from any Git repository:

git add-new [-A] <file1> [file2] [file3] ...

Options

  • -A — Add all untracked files (respects .gitignore).
    • Mutually exclusive with file arguments. Do not combine -A with paths.

Usage Examples

# Stage a single new file
git add-new src/NewComponent.js

# Stage multiple new files
git add-new src/NewComponent.js src/NewStyle.css docs/API.md

# Stage all untracked files (respects .gitignore)
git add-new -A

# After running git-add-new, use VS Code or git add -p to selectively stage
git add -p  # Interactive staging

Workflow

  1. Create your new file(s)
  2. Run git add-new <files> (or git add-new -A) instead of git add <files>
  3. Open VS Code or run git add -p to see pure additions (all green lines)
  4. Selectively stage the parts you want
  5. Commit as usual

Behavior and Notes

  • Only untracked files are processed. Tracked files are skipped with a warning.
  • -A cannot be combined with explicit file paths; using both will error.
  • Non-existent paths are reported and skipped.
  • This tool does not replace git add for normal staging; it is specifically for preparing new files to show as pure additions in diff viewers.

Safety Features

  • Checks if you're in a Git repository
  • Skips files that don't exist
  • Handles already-tracked files gracefully
  • Uses process-specific backup names to avoid conflicts
  • Provides colored status output

Why Use This?

  • Better code review: All lines show as additions (green) in diff viewers
  • Easier partial staging: In VS Code, you can easily see what you're adding
  • Cleaner diffs: Avoid confusing "modified" status for brand new files
  • Team consistency: Everyone sees the same clean addition diffs

License

MIT — see LICENSE.

About

A Git plugin that stages new files as pure additions

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages