如何将文件夹添加到 git 存储库?

How to add folders to git repository?

我想发布一些我用 java 创建的关于 MMU 的项目。 项目文件夹实际上包含两个单独的文件夹:第一个用于客户端,第二个用于服务器。

当然,要实现该目标,第一步是在我自己的 GitHub 站点中创建一个新的存储库。所以我做到了。

然后,我尝试尝试以下操作以在此存储库中添加相关文件夹:

1) 直接通过GitHub :

我在浏览器中单击了我的存储库,然后单击了上传文件。但是,上传整个文件夹以便 GitHub 保留我的文件夹中的文件和文件夹的层次结构失败了,因为它无法上传 select 文件夹。

我也尝试拖放文件夹,但总是出现以下错误:" Yowza, that’s a big file. Try again with a file smaller than 25MB.",即使我要上传的文件小于 25MB。

2) 通过使用 git-bash 命令行:

根据此 link https://github.community/t5/How-to-use-Git-and-GitHub/How-to-upload-an-entire-folder/td-p/8516,键入以下命令应该可以实现将整个文件夹添加到存储库中的目标:

git init

git add <folder1> <folder2> <etc.>

git commit -m "Your message about the commit"

git remote add origin https://github.com/yourUsername/yourRepository.git

git push -u origin master

git push origin master

但是在我输入命令:git add 之后,我收到以下错误:

bash: syntax error near unexpected token `<'

那么如何将整个文件夹添加到存储库中?

如有任何帮助,我们将不胜感激。

当教程说 <folder1> 时,只需使用没有 < > 的文件夹名称,即 folder1,而不是 <folder1><folder1> 只是您的文件夹的占位符。

例如,如果我想添加 my_cool_folder,我会执行以下操作:

git add my_cool_folder
git commit -m "I added my_cool_folder"
git push

1) git init

2)git add client server(客户端和服务器分别是文件夹1和文件夹2)

3) git commit -m "added client and server folders"

其余步骤相同。

转到 project_folder 所在的本地存储库。执行这些命令,将在 github.com.

上的你的存储库中添加 project_folder