Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make Git "add --all" by default?

I just ran into this message:

$ git add .
warning: You ran 'git add' with neither '-A (--all)' or '--ignore-removal',
whose behaviour will change in Git 2.0 with respect to paths you removed.
Paths like 'README.md' that are
removed from your working tree are ignored with this version of Git.

* 'git add --ignore-removal <pathspec>', which is the current default,
  ignores paths you removed from your working tree.

* 'git add --all <pathspec>' will let you also record the removals.

Run 'git status' to check the paths you removed from your working tree.

I think setting --all is a pretty sane default, since I can reset if something was added unexpectedly. How can I make that behavior default?

like image 442
Bengt Avatar asked Oct 17 '13 00:10

Bengt


People also ask

How do you git add all?

To add and commit files to a Git repositoryEnter git add --all at the command line prompt in your local project directory to add the files or changes to the repository. Enter git status to see the changes to be committed.

How does Option change behavior of git add command?

This option adds another level of functionality to the commit command. Passing this option will modify the last commit. Instead of creating a new commit, staged changes will be added to the previous commit.

Do I need to git add everytime?

You don't need to use git add every time you commit, git commit -am "message" will add to the commit everything that has been modified.

How do I add all Java files to git?

Just use git add *\*. java . This will add all . java files in root directory and all subdirectories.


1 Answers

The warning you see comes from commit ccc663b, itself reworking commit 45c45e3.

That second commit does include:

git add: start preparing for "git add <pathspec>..." to default to "-A"

Plan to eventually make "git add" pretend as if "-A" is given when there is a pathspec on the command line.
When resolving a conflict to remove a path, the current code tells you to "git rm $path", but with such a change, you will be able to say "git add $path" (of course you can do "git add -A $path" today).

So with Git 2.0, git add . will do what you want, but right now, a git alias is the way to get this by default.

git config alias.a 'add -A .'

[alias] 
  a = add -A .

This is now (March 2014) registered for the next release, with commit 160c4b1 and commit fdc97ab, for the next Git 2.0 (Q2 2014).

like image 93
VonC Avatar answered Sep 20 '22 07:09

VonC