如何将文件夹添加到Git仓库?

4
我想发布我用Java创建的MMU相关项目。实际上,该项目文件夹包含两个独立的文件夹:第一个是客户端,第二个是服务器端。
当然,要实现这个目标,第一步是在我的GitHub网站上创建一个新的存储库。所以我做了。
接下来,我尝试添加与此存储库相关的文件夹,以下是我尝试过的方法:
1)直接通过GitHub: 我在浏览器中单击我的存储库,然后单击上传文件。但是,上传整个文件夹以使GitHub保留文件夹中文件和文件夹的层次结构是失败的,因为它无法选择要上传的文件夹。
我还尝试将文件夹拖放到页面中,但它总是会出现以下错误:" Yowza, that’s a big file. Try again with a file smaller than 25MB.",即使我要上传的文件都远小于25MB。
2)使用git-bash命令行: 根据此链接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 `<'

你如何将整个文件夹添加到仓库中?
任何帮助都将不胜感激。

1
<folder1> 指的是一个随机文件夹。如果文件夹的名称是 foo,请使用 git add foo 而不是 git add <foo> - ElpieKay
你可以尝试这个基础教程:http://schacon.github.io/git/gittutorial.html - shrikant1712
3个回答

4
  • git init(初始化)
  • git add project_folder(添加项目文件夹)
  • git commit -m "Adding new Project"(提交变更,注明“添加新的项目”)
  • git remote add origin https://github.com/yourUsername/yourRepository.git(将本地仓库关联到名为 origin 的远程仓库)
  • git push -u -f origin master(将本地代码推送至 origin 远程仓库的 master 分支并强制更新)

进入存放项目文件夹的本地仓库,执行以上命令即可将 project_folder 添加到 github.com 上的 yourRepository 中。


1
当教程中提到<folder1>时,只需使用文件夹名称而不需要包含<>符号,即使用folder1而不是<folder1><folder1>仅是您的文件夹的占位符。
例如,如果我想添加my_cool_folder,我会执行以下操作:
git add my_cool_folder
git commit -m "I added my_cool_folder"
git push

0

1) git init

2) git add client server(client和server是文件夹1和文件夹2)

3) git commit -m "添加了client和server文件夹"

其余步骤相同。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接