Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git add multiple files at once

Tags:

git

add

I had this project with a lot .c files in source directory,then I make the project, there is .o files inside of the project, I also want to push these files to repository,so instead of add each .o which is possible but...,how to add .o files easily?

like image 282
user1051003 Avatar asked Dec 07 '11 08:12

user1051003


People also ask

Can you add multiple files with git add?

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. Now commit your files, the editions or addition made in the files will now be saved.

How do you git add all files in a folder?

The easiest way to add all files to your Git repository is to use the “git add” command followed by the “-A” option for “all”. In this case, the new (or untracked), deleted and modified files will be added to your Git staging area. We also say that they will be staged.

Can we commit multiple files in git?

Yes! This is going to work!


2 Answers

How to add multiple files with different extensions to git all at one time...

You can add to git by explicitly listing each file with spaces as delimiters.

$ git add file-name-1.php file-name-2.js file-name-3.html … 

The accepted answer is perfect for the OP’s specific case. But I got here—via Google—needing to add multiple files with different extensions. Posting here in case you miss this similar answer to a similar question.

Don't forget about interactive staging

Git interactive staging can also work wonders. To enter interactive staging (aka: adding, removing files):

 $ git add -i 
like image 192
elbowlobstercowstand Avatar answered Oct 09 '22 13:10

elbowlobstercowstand


Putting aside the fact, that this is just a terrible idea, you can add them as any other file:

git add *.o git commit -m "Committing compiled files, which is bad" 

Of course instead of git add *.o you can use git add */*.o or even find -name *.o | while read x; do git add $x; done

like image 32
Šimon Tóth Avatar answered Oct 09 '22 15:10

Šimon Tóth