41

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?

4
  • 3
    Is it really a good idea to store object files in your repository? Seems like a strange thing to me... Commented Dec 7, 2011 at 8:04
  • 4
    Why would you possibly want to add .o files? Commented Dec 7, 2011 at 8:04
  • 2
    Unless you are doing something very special you definitely don't want to add any compiled files into the repository. Commented Dec 7, 2011 at 8:05
  • 2
    Just a sidenote: Check if *.o is being ignored in your .gitignore file. It is fairly uncommon to add .o files to the source repository. In that case you will have to force add i.e. git add -f <files> Commented Dec 7, 2011 at 8:17

3 Answers 3

75

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
Sign up to request clarification or add additional context in comments.

Comments

44

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

3 Comments

the reason I did this is this repository is just for me and my friend,the project took 20 minutes to compile on his computer, and I am testing if this might save a little bit of time.and this helps a lot thanks
find -name '*.o' -type f -exec git add {} \;
Seems like a duplicate question, Checkout this answer too, stackoverflow.com/a/67543452/12415637
7

Maybe you have ignored your .o file, check out your .gitignore file if it exists.
Otherwise, you can add all files just by:

$ git add .
$ git commit -am "You message"

However, I dot think it's a good idea to trace the .o files. It's binary file, you'll get these files whenever you do build. Ignore it is a good practice. :)

2 Comments

Note that this will add all files (not just the .o)
@Let_Me_Be ya, I figured he may want thin one. :p

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.