Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Salesforce
  3. Question
Salesforce

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

Asked by Yash Raj Jul 6, 2021 9.7K views 3 answers
Share

About this question

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?

Your answer

3 Answers

Ranjana Admin JanBask Expert Latest answer

Answered on Mar 18, 2025

If you want to add all files in a folder recursively to a Git repository, here is how you can do it

1 Basic Command to Add All Files

To add all files inside a folder and its subfolders, use

  git add foldername

  • This will recursively add all files and subfolders inside the specified folder
  • If you want to add everything in the current directory, use

  git add .

This will include all new, modified, and deleted files

2 Checking What Will Be Added

Before committing, you can check what is being staged by running

  git status

This will show a list of tracked and untracked files

3 Committing the Changes

Once all files are added, commit them using

  git commit -m "Added all files in the folder"

Replace the message with something meaningful

4 Ignoring Unwanted Files

If you do not want to add certain files, create a .gitignore file and list the files or folders you want to ignore

 Example

node_modules
*.log
*.tmp

Then run

git add .
git commit -m "Added all required files"

5 Final Thoughts

  • Use git add foldername to add a specific folder
  • Use git add . to add everything in the current directory
  • Always check git status before committing to avoid adding unwanted files
  • Use .gitignore to exclude unnecessary files


Was this helpful?

Ranjana Admin JanBask Expert

Answered on May 3, 2024

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.

Was this helpful?

More Salesforce discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Salesforce Blogs

Guides, tips and career advice on Salesforce from JanBask experts.