Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git add all unstaged/untracked files with a single command

Tags:

git


pardon the newbie question. I'm looking for a quick but safe option to add all unstaged/untracked files (returned by "git status") with one command. Is it safe to use from the project root:

git add *

Any drawback? Thanks

like image 822
Carla Avatar asked Jan 18 '26 13:01

Carla


1 Answers

* is a wildcard expanded by the shell. It won't match "hidden" files (those whose names start with .) and it will fail if there are too many files in the current directory to fit on the command line.

A solution without these drawbacks is:

git add .

This works because git adds the contents of directories recursively, so telling it to add . (the current directory) adds everything.

Another difference relates to .gitignore patterns. If you have a file in the current directory that matches a pattern in .gitignore, then git add . will just silently ignore it. But shell wildcards don't know about .gitignore, so when you do git add *, the ignored file will be explicitly added to the git add command, which causes git add to fail with an error.

like image 53
melpomene Avatar answered Jan 21 '26 09:01

melpomene