开发者

How do I automatically add new files to Git?

I know I can just do git add for all the files, but I got a开发者_开发知识库 ton of files. Is there a way to do something like "git add *.h", or "git add *.py" ?


Yes you can say git add *.py Make sure you have done git init before doing this.

To add all files in a folder you can simply say git add .


When you are using something like *.py, you have to understand that the shell is doing the extension and not git. It won't consider subdirectories for the extension, and also, you end up adding ignored files, which is something you probably don't want ( git add by default doesn't add ignored files, unless the file is explicitly specified, which is the case when shell extension happens)

What you can do is something like below:

git add /\*.py

The asterisk * is quoted from the shell in this and will include the files from subdirectories. And you won't end up adding ignored files as well.

It is frowned upon to do git add . - you don't know exactly what you end up adding. I wouldn't recommend doing it.

As for your other problem while pushing, first you have to have a proper remote setup:

git remote add origin yourremoterepourl


git add . will add all the files - new and edited, in the current directory and sub-directories recursively. Note that .can be replaced by any directory in the current git repo.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜