git 如何将我当前的项目添加到现有的 GitHub 存储库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16897723/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to add my current project to an already existing GitHub repository
提问by Vor
I'm very new to Git. I've been searching for an answer, but I couldn't find one.
我对 Git 很陌生。我一直在寻找答案,但找不到。
In my computer I have a project folder like this:
在我的电脑中,我有一个这样的项目文件夹:
project_a
--some_folder
--another_folder
--.git
And I have a repository on GitHub, let's say https://github.com/company/our_repo.git
. Under this repository I have some folders. So my goal is to put my project_a
under trunk/bin
. How do I achieve this? (Again, I'm very very very new.)
我在 GitHub 上有一个存储库,比方说https://github.com/company/our_repo.git
。在这个存储库下,我有一些文件夹。所以,我的目标是把我project_a
下trunk/bin
。我如何实现这一目标?(同样,我非常非常非常新。)
回答by Ziyaddin Sadigov
Open your Terminal, access to this folder and write:
打开您的终端,访问此文件夹并写入:
git init
git add .
git commit -m "my commit"
git remote set-url origin [email protected]:username/repo.git
git push origin master
回答by Adam
I had more luck with navigating in my terminal to the directory I wanted to add to the repository, then (assuming you're working on a branch called master):
我有更多的运气在我的终端中导航到我想添加到存储库的目录,然后(假设您正在一个名为 master 的分支上工作):
git init
git add .
git commit -m "my commit"
git remote add origin <remote repository URL>
git push origin master
Here's a link to an article explaining how to do it in more detail: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/
这是一篇文章的链接,更详细地解释了如何做到这一点:https: //help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/
Note that you won't be able to run the "git add ." line if the directory in question is open.
请注意,您将无法运行“git add”。如果有问题的目录是打开的,则行。
回答by Ajaya Mandal
All the answers above seems to guide about creating a new repository in git but the question is about adding a folder to existing repo. To do that following steps can be followed.
上面的所有答案似乎都指导在 git 中创建一个新的存储库,但问题是关于向现有存储库添加一个文件夹。要做到这一点,可以遵循以下步骤。
- Clone your existing repo using following command:
git clone https://github.com/company/our_repo.git
- Manually take your project folder to the desired location i.e.
trunk/bin
- Now commit and then push in the repo using the commands:
git commit -m "message"
andgit push origin master
- 使用以下命令克隆您现有的存储库:
git clone https://github.com/company/our_repo.git
- 手动将您的项目文件夹带到所需的位置,即
trunk/bin
- 现在提交,然后使用以下命令推送 repo:
git commit -m "message"
和git push origin master
回答by Vikram Shekhawat
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
OR
或者
git push origin master
if you get any error, you may use it
如果您遇到任何错误,您可以使用它
git push -f origin master
回答by Darshan Jain
I think it is very preferable if you first pull the existing Github repo on the local and then add the new files to the Github repo
我认为如果您首先在本地拉取现有的 Github 存储库,然后将新文件添加到 Github 存储库中,这是非常可取的
This link will help: https://stackoverflow.com/a/61285076/5840973
此链接将有所帮助:https: //stackoverflow.com/a/61285076/5840973