This write-up will explain the method to commit a whole folder in Git.
How to Git Commit a Whole Folder?
To commit a whole folder in Git, first, switch to the local repository. Then, redirect to the particular folder and create some files in it. Next, use the “git add <“folder-path”>” command to add the whole folder to the Git staging area. After that, run the “git commit” command along with the folder path to commit the whole folder, including all files. Lastly, verify the committed changes.
Check out the following steps for a practical demonstration!
Step 1: Navigate to Desired Directory
First, switch to the particular local repository with the help of the following command:
Step 2: View List of Files
Then, utilize the “ls” command to display the list of files and folders in the repository:
Here, it can be observed that there are three files and one folder in the working directory:
Step 3: Navigate to Particular Folder
Next, redirect to the particular folder using “cd” along with the folder name:
Step 4: Create Files in Folder
Now, use the “touch” command and generate some files in the folder:
Step 5: Check Git Status
View the Git status to check the state of the working directory:
The below output indicates that the “subFolder” needs to be tracked and commit:
Step 6: Track Folder
Now, add the whole folder to the Git index for tracking purposes using the “git add <“folder-path”>” command:
Step 7: Commit Folder
Next, run the “git commit” command along with the folder path and commit message to commit the whole folder:
Step 8: Verify Committed Changes
Check the Git status again to view the committed changes:
According to the below image, the Git status is clear and there is nothing to commit:
Step 9: Check Reference Log
Lastly, view the commit history by checking the reference log:
It can be observed in the below output that the whole folder has been committed successfully:
We have efficiently explained the process of committing a whole folder in Git.
Conclusion
To commit the whole folder in Git, first, redirect to that particular folder. Then, run the “git add” and “git commit” commands along with the folder path to track and commit the whole folder, including all its files. Lastly, verify changes by checking Git status and reference log. This write-up explained the method to commit a whole folder in Git.