How to Add All Files in a Folder to Commit in Git

John Wachira Feb 02, 2024
  1. Add All Files in a Folder to Commit in Git
  2. Alternative Way to Add All Files in a Folder to Commit in Git
How to Add All Files in a Folder to Commit in Git

This article will discuss the steps necessary to add all the files within a folder for commit.

If you have a folder with a dozen files, adding files one by one can be tedious. Luckily, Git allows us to add all content of a folder for commit.

Let’s see how we can do this.

Add All Files in a Folder to Commit in Git

The image below has a Git repository with several untracked folders containing different files.

Git Add Folder to Commit - Untracked Folders

Let’s assume we want to add the Work samples/ folder. How do we go about this?

We can run the git add command in the context shown below;

$ git add "Work samples/"

We have included the "" because the folder name has spaces. This command should add all the files in the Work samples/ folder.

Let’s check our index.

$ git status

Git Add Folder to Commit - Git Status Output 1

That’s much faster and cleaner than adding them one by one.

Alternative Way to Add All Files in a Folder to Commit in Git

Alternatively, you can cd into the folder and run the command, as shown below:

$ cd "Work samples/"

To add all files within our folder, run the following:

git add .

Let’s check our index.

$ git status

Git Add Folder to Commit - Git Status Output 2

All our files have been added to our index.

To commit:

$ git commit -m"commit message"

In conclusion, you can add a whole folder to commit in Git. Make sure you are above the folder you intend to add.

You can also use the git add command with a dot to add all files in a folder. And when specifying the folder name, use "" if the folder name has spaces.

Author: John Wachira
John Wachira avatar John Wachira avatar

John is a Git and PowerShell geek. He uses his expertise in the version control system to help businesses manage their source code. According to him, Shell scripting is the number one choice for automating the management of systems.

LinkedIn

Related Article - Git Add