How to Recursively Add Files and Folders in Git

Sometimes, Git users encounter situations where they have to create a new file or update some project folders, subfolders, and files that already exist in Git. For this purpose, Git offers the “$ git add <file_name>” command. This command tracks the file from the working directory to the staging area, indicating that it is ready to push to the remote Git repository.

This study will provide the procedure of recursively adding single and multiple files and folders in Git.

How to Recursively Add Single File and Folder in Git?

If we want to add a single file and folder in Git, create a new Git directory. Then, create the required file using the Git available command. Lastly, recursively add it to Git. To do so, follow the below-given instructions.

Step 1: Open Git Bash

Search and open the “Git Bash” using the “Startup” menu:

Step 2: Move to Folder

Navigate to the folder in which you want to create Git directory:

$ cd "C:\Users\nazma\Git"


Step 3: Create Git Directory

Now, create a new Git directory by utilizing the “mkdir” command:

$ mkdir test_dir


Step 4: Navigate to Git Directory

Next, run the “cd” command and move to the newly created Git directory:

$ cd test_dir


Step 5: Create New File

Create a new text file “file1.txt” in the Git directory with the provided “touch” command:

$ touch file1.txt


Step 6: Recursively Add File

Execute the “git add” command and specify the filename to add it recursively into the Git directory:

$ git add file1.txt


Step 7: Commit Changes

Commit changes to the Git local repository with a message using the “-m” option:

$ git commit -m "one file added"

As you can see, we have successfully added the file and committed the message to the Git repository:

Want to add multiple files recursively? Head towards the next section!

How to Recursively Add Multiple Files and Folders in Git?

There can be a situation when you want to simultaneously add more than one file or folder to the Git repository. To do so, follow the below instructions.

Step 1: Move to Git Repository

First, move to the Git local repository folder:

$ cd "C:\Users\nazma\Git\Demo_dir"


Step 2: Create Files

Now, execute the “touch” command to create multiple files with the help of the “touch” command:

$ touch file1.txt file2.txt file3.txt


Step 3: Recursively Add Multiple Files

Next, add the files to the Git repository using the “git add .” command:

$ git add .

Here the “.” denotes that all of the files will be added:

Step 4: Commit Changes

Lastly, execute the “git commit” command with the “-m” option to commit message:

$ git commit -m "multiple files added"

Below output indicates that multiple files are added simultaneously to the Git local repository:

We have explained how to recursively add files and folders in Git.


To recursively add files and folders in Git, navigate to the folder, create a folder, and create single or multiple files with the help of the “$ touch” command. Then, execute the “$ git add <file_name>” command to add a file in the staging area from the working directory. Moreover, to add multiple files to the Git repository, use the “$ git add .” command. This study demonstrated the method of recursively adding single and multiple files and folders in Git.

About the author

Maria Naz

I hold a master's degree in computer science. I am passionate about my work, exploring new technologies, learning programming languages, and I love to share my knowledge with the world.