Git add multiple files-How to add multiple files in git for a single commit?

5.5K    Asked by Bhaanumatishukla in SQL Server , Asked on Apr 19, 2021

 I made changes to two files in a different directory, How can I add the two files for a single commit. can I do like, add the first, then change the directory to the second file and add the second file finally do the commit. Is this going to work?

You can add all the files using the git add command like below for all the files you want to add, which will add all your files to the staging area, which means the files are ready to be committed.


git add file1.txt folder/file2.txt file3.txt file4.txt file5.txt

Now commit your files, the editions or addition made in the files will now be saved.

git commit file1.txt folder/file2.txt file3.txt -m "Some_message"

You will have added these files

file1.txt

folder/file2.txt

file3.txt

file4.txt

to the staging area and then committed with the same message.

file1.txt

folder/file2.txt

file3.txt

Note: git add multiple file in the same format.

Use the git add in the same format command, followed by a list of space-separated filenames. Include paths if in other directories, e.g. directory-name/file-name. You see the * before the number? that means that the file was added. This will add all the files to the specified subfolder.



Your Answer

Interviews

Parent Categories