This write-up will illustrate the procedure to add multiple files in Git for a single commit.
How to Add Multiple/Various Files in Git for a Single Commit?
To add multiple files in the local Git repository in a single commit, try out the below-mentioned steps:
- Switch to the local repository.
- Create/make multiple files.
- Add all files to the Git index.
- Commit multiple desired files using the “git commit <file1-name> <file2-name> <file3-name> -m “<commit-message>”” command.
- Verify changes.
Step 1: Navigate to Local Repository
First, redirect to the particular local directory:
Step 2: Create Multiple Files
Then, create or make some files in the current repository using the “touch” command:
Here, “File1.txt”, “File2.txt”, “test.txt” and “demo.txt” are the names of the files that we want to create:
Step 3: Stage All Files
Next, type out the provided command to add all the files to the Git staging area:
Step 4: Check Git Status
After that, view the current status of the repository:
The below output shows four files that have been staged:
Step 5: Commit Multiple Files
Now, utilize the “git commit” command along with the desired commit message and specify the file names that you want to commit. For instance, we want to commit three files that are “File1.txt”, “test.txt” and “demo.txt”:
Step 6: Verify Changes
To ensure that the files have been committed or not, run the given-provided command:
In the below output the name of three committed files can be seen:
Step 7: View Current Status
Lastly, check the Git status to view the uncommitted file:
The Git status shows the file that we did not commit:
That was all about adding multiple files in Git for a single commit.
Conclusion
To add multiple files in Git for a single commit, first, redirect to the local repository. Then, create multiple files and stage them. Next, utilize the “git commit <file1-name> <file2-name> <file3-name> -m “<commit-message>”” command to add multiple desired files to the local Git repository in a single commit. Lastly, verify changes. This write-up illustrated the method to add multiple files in Git for a single commit.