How to add multiple files to Git at the same time -git add multiple files ?

4.1K    Asked by DylanForsyth in SQL Server , Asked on Apr 19, 2021

I am new to git. I have added new files ( a lot ) to the folder/project ( git local repository).

I went through online tutorials and forums and see I can do

     git commit -a

So I go to the base folder of the repository and do a

    sudo git commit -a

But then, some screens comes up and asks me to add a comment which I do. I do not know how to proceed or exit. I do not want to mess up so I did ctrl + Z and did not do anything.

Can you guys please outline the commands I need to use?

git commit -a 

or

git push

How git add multiple files ?

Answered by Dylan Forsyth

To add all the changes you've made:

          git add .

To commit them:

          git commit -m "MY MESSAGE HERE"

To push your committed changes from your local repository to your remote repository:

          <a href="https://www.janbasktraining.com/blog/git-push-vs-git-push-origin/"><a href="https://www.janbasktraining.com/community/sql-server/how-can-we-find-the-stored-procedure-in-the-database-if-we-have-just-some-idea-of-the-procedure-name">git push origin</a></a> master

You might have to type in your username/password for github after this. These steps will help you to add all files to the staging area in git.

Note:

To add and commit files to a Git repository

Create your new files or edit existing files in your local project directory. Enter git add --all at the command line prompt in your local project directory to add the files or changes to the repository. Enter git status to see the changes to be committed.



Your Answer

Answer (1)

To add multiple files to Git at the same time, you can use the git add command followed by the names or paths of the files you want to add. Here's how you can do it:

git add file1 file2 file3

 Replace file1, file2, and file3 with the actual names or paths of the files you want to add. You can add as many files as needed by separating them with spaces.

git add .

This command adds all untracked files and stages them for the next commit. However, be cautious when using git add . as it adds all untracked files, including those you might not want to commit.

After adding the files, remember to commit your changes using git commit. For example:

Alternatively, if you want to add all files within a specific directory and its subdirectories, you can use the following command:

This creates a new commit with the changes you've staged using git add.


6 Months

Interviews

Parent Categories