如何将我当前的项目添加到现有的github仓库

Vor*_*Vor 32 git version-control github

我对git很新.我一直在寻找答案,却找不到答案.在我的电脑中,我有一个像这样的项目文件夹:

project_a
--some_folder
--another_folder
--.git
Run Code Online (Sandbox Code Playgroud)

我在github上有一个存储库,让我们说https://github.com/company/our_repo.git在这个回购下我有一些文件夹.所以我的目标是让我project_a失望trunk/bin.能否请你告诉我如何实现这个目标.(再次,我非常非常新)

Ziy*_*gov 47

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

git init
git add .
git commit -m "my commit"
git remote set-url origin git@github.com:username/repo.git
git push origin master
Run Code Online (Sandbox Code Playgroud)

  • 需要注意的是:如果您是第一次对文件夹执行此操作,那么您应该使用 `git remote add` 而不是 `git remote set-url` 。 (12认同)
  • 然后首先将现有repo克隆到本地计算机中的文件夹.然后将project_a添加到trunk/bin文件夹.然后推送到github. (8认同)
  • 但我的目标是将我的`project_a`放在现有的`repo`下,这样在github上看起来就像`repo/trunk/bin/project_a` (2认同)

Ada*_*dam 26

我有幸导航到我想要添加到存储库的目录(使用/替换为/的cd文件路径),然后:

    git init
    git add .
    git commit -m "my commit"
    git remote add origin <remote repository URL>
    git push origin master
Run Code Online (Sandbox Code Playgroud)

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

请注意,您将无法运行"git add".如果有问题的目录是打开的话

  • 适合我.被接受的不是.谢谢 (5认同)
  • 工作完美无缺。 (2认同)

Vik*_*wat 11

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
Run Code Online (Sandbox Code Playgroud)

或者

git push origin master
Run Code Online (Sandbox Code Playgroud)

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

git push -f origin master
Run Code Online (Sandbox Code Playgroud)

  • 这是 2021 年对我有用的答案。 (2认同)

Aja*_*dal 11

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

  • 使用以下命令克隆现有仓库: git clone https://github.com/company/our_repo.git
  • 手动将项目文件夹移动到所需位置,即 trunk/bin
  • 现在提交然后使用命令推送repo: git commit -m "message"git push origin master


小智 8

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

git init
git add *
git commit -m "Initial commit"
git branch -M main
git remote add origin <repo url>
git push -f origin main
Run Code Online (Sandbox Code Playgroud)