Git add all files in folder-Recursively add the entire folder to a repository

2.6K    Asked by Yashraj in Salesforce , Asked on Jul 6, 2021

I am trying to add a branch to the master branch on GitHub and push a folder onto that branch.

The folder structure of the branch looks like - SocialApp/SourceCode/DevTrunk/SocialApp and all the source code files are in the last folder.

I am using the following Git commands:

git add *
git commit -m with the message
git push

This is pushing only the first folder "SocialApp" onto GitHub and ignoring the folder SourceCode that is inside the folder. How git add recursive?

Answered by debbie Jha

For this case:

Go to .gitignore file and check whether the subdirectory is ignored or not ignored.

And then you could do:

git add --all

git commit -am ""

git push

This will add the entire folder to a repository.

Note: To recursively add all files or folders and also sub folders to the staging area of git, we can either call “git add -A” or “git add –all”, it will add all files in the project workspace to the staging area, irrespective of location from where this command is executing.



Your Answer

Answer (1)

To add all files in a folder, including subfolders, to a Git repository, you can use the following commands:


git add .
git commit -m "Add all files recursively"

This assumes that you are already in the root directory of your Git repository.

Explanation:

git add .: This command adds all changes in the current directory and its subdirectories to the staging area. The . represents the current directory. By default, this command will recursively add all files and folders.

git commit -m "Add all files recursively": This command commits the changes added to the staging area with a commit message "Add all files recursively". You can replace the commit message with any message that describes the changes you're committing.

After running these commands, all files in the folder, including those in subfolders, will be staged and committed to the repository.

5 Months

Interviews

Parent Categories