| by Arround The Web | No comments

How to Git Commit a Whole Folder?

A folder is used to store and organize files and data. Sometimes, while working on Git, developers create multiple folders to perform different operations. Each folder contains many files. So, it becomes hard to stage and commit all the files separately. For the corresponding purpose, developers commit the whole folder at once.

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:

$ cd "C:\Git\new_repos"

Step 2: View List of Files
Then, utilize the “ls” command to display the list of files and folders in the repository:

$ ls

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:

$ cd subFolder

Step 4: Create Files in Folder
Now, use the “touch” command and generate some files in the folder:

$ touch F1.txt F2.txt F3.py

Step 5: Check Git Status
View the Git status to check the state of the working directory:

$ git status

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:

$ git add "C:\Git\new_repos\subFolder"

Step 7: Commit Folder
Next, run the “git commit” command along with the folder path and commit message to commit the whole folder:

$ git commit "C:\Git\new_repos\subFolder" -m "SubFolder added"

Step 8: Verify Committed Changes
Check the Git status again to view the committed changes:

$ git status

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:

$ git reflog

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.

Share Button

Source: linuxhint.com

Leave a Reply