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.
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:
- Temporarily moves your file to a backup
- Creates an empty file with the same name
- Stages the empty file (
git add) - 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.
- Git
- Bash 4.0 or newer
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-newVerify the installation:
git add-new -hOnce installed, the plugin works from any Git repository:
git add-new [-A] <file1> [file2] [file3] ...-A— Add all untracked files (respects.gitignore).- Mutually exclusive with file arguments. Do not combine
-Awith paths.
- Mutually exclusive with file arguments. Do not combine
# 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- Create your new file(s)
- Run
git add-new <files>(orgit add-new -A) instead ofgit add <files> - Open VS Code or run
git add -pto see pure additions (all green lines) - Selectively stage the parts you want
- Commit as usual
- Only untracked files are processed. Tracked files are skipped with a warning.
-Acannot be combined with explicit file paths; using both will error.- Non-existent paths are reported and skipped.
- This tool does not replace
git addfor normal staging; it is specifically for preparing new files to show as pure additions in diff viewers.
- 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
- 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
MIT — see LICENSE.
