74

我对 Git 很陌生。我一直在寻找答案,但我找不到答案。

在我的计算机中,我有一个这样的项目文件夹:

project_a
--some_folder
--another_folder
--.git

我在 GitHub 上有一个存储库,比如说https://github.com/company/our_repo.git. 在这个存储库下我有一些文件夹。所以我的目标是把我project_atrunk/bin。我如何实现这一目标?(同样,我非常非常非常新。)

4

7 回答 7

86

打开您的终端,访问此文件夹并写入:

git init
git add .
git commit -m "my commit"
git remote set-url origin git@github.com:username/repo.git
git push origin master
于 2013-06-03T13:23:25.567 回答
60

我在终端中导航到我想要添加到存储库的目录时更幸运,然后(假设您正在处理一个名为 master 的分支):

    git init
    git add .
    git commit -m "my commit"
    git remote add origin <remote repository URL>
    git push origin master

这是一篇文章的链接,详细解释了如何做到这一点:https ://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/

请注意,您将无法运行“git add”。如果有问题的目录是打开的,则行。

于 2014-12-01T07:03:24.370 回答
24

上面的所有答案似乎都可以指导在 git 中创建新存储库,但问题是关于将文件夹添加到现有存储库。为此,可以遵循以下步骤。

  • 使用以下命令克隆您现有的存储库: git clone https://github.com/company/our_repo.git
  • 手动将您的项目文件夹带到所需的位置,即trunk/bin
  • 现在提交,然后使用以下命令推入 repo: git commit -m "message"git push origin master
于 2018-06-25T07:18:36.713 回答
13
1. first create a git repostry.
2. second open git bash in  existing or uploading project.
3. perform git init 
4. git add .
5. git commit -m "print message"
6. git remote add github<repostry url>
7. git remote -v
8. git push github master

或者

git push origin master

如果您遇到任何错误,您可以使用它

git push -f origin master
于 2017-03-22T06:00:23.787 回答
3

-f当你要推送已经存在的 repo 时,你必须使用它。

git init
git add *
git commit -m "Initial commit"
git branch -M main
git remote add origin <repo url>
git push -f origin main
于 2021-10-29T10:09:18.580 回答
2

我认为最好先将现有的 Github repo 拉到本地,然后将新文件添加到 Github repo

此链接将有所帮助:https ://stackoverflow.com/a/61285076/5840973

于 2020-04-18T06:36:23.397 回答
1

假设我想将FreeRTOS存储库(URL 为https://github.com/FreeRTOS/FreeRTOS-Kernel.git)添加到我的存储库中,示例 URLhttps://github.com/username/example作为子模块

git submodule add https://github.com/FreeRTOS/FreeRTOS-Kernel.git
git add .
git commit -m 'add a submodule'
git push

使用 HTTPS 进行克隆:

git clone https://github.com/username/example.git --recurse-submodules

使用 SSH:

git clone git@github.com:username/example.git --recurse-submodules

如果您在没有使用--recurse-submodules参数的情况下下载了 repo,则需要运行:

git submodule update --init --recursive
于 2021-01-05T06:13:21.537 回答