DEV Community

Cover image for Git add . vs Git add -a vs Git add -u
Mohamed Yahia
Mohamed Yahia

Posted on • Edited on

Git add . vs Git add -a vs Git add -u

The difference between those three commands can be inferred from their parameters and flags.

Git add . 
Enter fullscreen mode Exit fullscreen mode

What does . mean?

That's right. It means the current directory. So, git add . adds all files and folders located in the current directory including hidden files/folders.

Git add -a
Enter fullscreen mode Exit fullscreen mode

-a flag is the shorter version of the --all flag, and as can be inferred it means adding all files and folders, but isn't that what git add . does? Well, you missed "the current directory" part. I know you haven't missed it, smart guy, I am just playing with you .

Getting back to the point, git add -a adds all files or folders in the whole repository, not just the current directory.

So that means if you modified a file in the repo main directory, cd'ed into a sub-directory, modified another file then ran the earlier command git add . you will only add the file in the subdirectory.

git add -u
Enter fullscreen mode Exit fullscreen mode

-u flag is the shorter version for --update flag, and again as can be inferred, it means updating files and folders but there is a caveat, new files/ folders are not tracked,

Image description

and thus they can't be updated. So basically that means modified and deleted files/folders are added but not newly created ones.

Top comments (0)