Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git: stage only new files

When I have:

  • dirty working directory,
  • dirty staging area,
  • and I copied some new files to the project,

how do I stage only the new ones?

git alias adduntracked=…
like image 702
takeshin Avatar asked Sep 14 '10 08:09

takeshin


People also ask

Is git add only for new files?

Adds all changes to existing files to the Staging Area. This includes changed files and deleted files - but not new files that aren't currently tracked by Git.

What command is used to stage only some changes in a file?

git add -p is basically "git add partial (or patch)" Patch mode allows you to stage parts of a changed file, instead of the entire file.

How do I add untracked files to stage?

The easiest way to add all files to your Git repository is to use the “git add” command followed by the “-A” option for “all”. In this case, the new (or untracked), deleted and modified files will be added to your Git staging area.


1 Answers

This alias will respect your ignore patterns (builtin, global and per-directory, as described by the help for git-ls-files --exclude-standard). It will run at the top level of your tree.

[alias]
adduntracked=!git add $(git ls-files -o --exclude-standard)
like image 98
bstpierre Avatar answered Oct 12 '22 23:10

bstpierre