Support People In Ukraine
Ukraine was invaded by Russia in the early morning of 24.02.2022, explosions thundered in Ukrainian cities, many civilians died, tens of millions are affected. Our army protects all Europe from the occupiers and it needs help now to restrain one of the biggest armies in the world. Please, donate a small amount.
I Am
Volodymyr Hudyma
<FrontEndDeveloper />
You Are Here: Home/Difference Between "git add -A", "git add ." and "git add -u"

Difference Between "git add -A", "git add ." and "git add -u"

September 08, 2021

Table Of Contents

    The most basic task any developer has when working with Git on a daily basis is adding files to be committed.

    Probably the vast majority of us use git add -A without knowing exactly what is going on behind the scenes when we use the -A flag, and whether there are no other options that suit our needs better.

    #1 - "git add -A"

    This command stages:

    • All changes
    • In all directories

    It is equivalent to git add --all.

    Command: git add -A

    #2 - "git add ."

    This command stages:

    • All changes
    • In the current directory and its subdirectories (if a file has been changed outside the directory where you run the git commands, it will not be staged)

    Command: git add .

    #3 - "git add -u"

    This command stages

    • All modifications and deletions (but no new files)
    • In all directories

    It is equivalent to git add --update.

    Command: git add -u

    Bonus Commands

    #1 - Stage A Single File

    If you want to stage a single file, run the git add command, specifying the path to the file:

    git add src/components/Button/Button.tsx

    #2 - Stage All Files Within A Specific Folder

    If you want to stage all files inside a specific folder, specify the path to that folder:

    git add src/components/

    #3 - Stage All Files With A Specific Extension

    If you want to stage all files with a specific extension, for example .txt, run the following command:

    git add -A *.txt

    #4 - Stage All Files But Removed

    If you want to stage all files excluding deleted, run the following command:

    git add --ignore-removal .

    Summary

    In this article, we have learned the main differences between the following commands: git add -A, git add . and git add -u.

    You may never need to know the difference if you do not want to, as it is quite easy to restore an incorrectly deployed file using the git restore --staged command.

    Newsletter
    Receive all new posts directly to your e-mail
    No spam, only quality content twice a week
    Let me know what you think about this article
    Click here to write response...