0
0
GitHow-ToBeginner · 3 min read

How to Add All Files in Git: Simple Commands Explained

To add all files in Git, use the command git add . which stages all new and modified files in the current directory and its subdirectories. Alternatively, git add -A also stages all changes including deletions across the entire repository.
📐

Syntax

The basic command to add all files in Git is git add .. Here:

  • git add tells Git to start tracking changes.
  • . means all files and folders in the current directory and below.

Another common syntax is git add -A which stages all changes including file deletions anywhere in the repository.

bash
git add .
git add -A
💻

Example

This example shows how to add all files in your project folder to Git's staging area before committing.

bash
$ git status
On branch main
No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)

	file1.txt
	dir/file2.txt

$ git add .

$ git status
On branch main

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

	new file:   file1.txt
	new file:   dir/file2.txt
Output
On branch main No commits yet Untracked files: (use "git add <file>..." to include in what will be committed) file1.txt dir/file2.txt On branch main Changes to be committed: (use "git rm --cached <file>..." to unstage) new file: file1.txt new file: dir/file2.txt
⚠️

Common Pitfalls

One common mistake is using git add * which only adds files in the current directory but ignores hidden files and changes in subdirectories. Also, git add . does not stage file deletions outside the current directory.

To avoid missing deletions or changes in other folders, use git add -A instead.

bash
$ git add *  # May miss hidden files and subfolders
$ git add .  # Adds all files in current folder and below, but not deletions outside
$ git add -A  # Correct way to add all changes including deletions everywhere
📊

Quick Reference

CommandDescription
git add .Add all new and modified files in current directory and subdirectories
git add -AAdd all changes including deletions across the entire repository
git add *Adds files only in current directory, ignores hidden and subfolders
git statusCheck which files are staged or unstaged

Key Takeaways

Use git add . to stage all new and modified files in the current folder and below.
Use git add -A to stage all changes including deletions anywhere in the repo.
Avoid git add * as it misses hidden files and subdirectories.
Always check staged files with git status before committing.