将现有项目推送到 Github [英] Push existing project into Github

查看:35
本文介绍了将现有项目推送到 Github的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含我的项目源的文件夹.我如何将这个项目推送到 Github 的存储库中?

I have a folder with my project sources. How I can push this project into Github's repository?

我尝试使用以下步骤:

  1. 我在 GitHub 上创建了空存储库.
  2. 我运行 git-bash 并输入 git init,所以在项目根目录中出现了 .git 文件夹.
  3. 我使用 git add sourcesFolderName
  4. 添加了一些文件到版本控制
  5. 我使用 git commit -m "initial commit"
  6. 提交了在上一步中添加的文件
  7. 我使用 git remote add MyProject <url>
  8. 指定了远程存储库
  9. 最后git push,但是没有推送到远程仓库...(没有授权失败)
  1. I created empty repository on GitHub.
  2. I run git-bash and typed git init, so inside project root appeared .git folder.
  3. I added some files to version control using git add sourcesFolderName
  4. I committed files added in previous step using git commit -m "initial commit"
  5. I specified remote repository using git remote add MyProject <url>
  6. Finally git push, but nothing is pushed to remote repo... (no authorization failure)

那么我如何将现有源代码推送到新创建的 github 存储库中?

So how I can push existing sources into newly created github repo?

推荐答案

git init
git add .
git commit -m "Initial commit"
git remote add origin <project url>
git push -f origin master

git push 上的 -f 选项强制推送.如果你不使用它,你会看到这样的错误:

The -f option on git push forces the push. If you don't use it, you'll see an error like this:

To git@github.com:roseperrone/project.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'git@github.com:roseperrone/project.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first merge the remote changes (e.g.,
hint: 'git pull') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

这篇关于将现有项目推送到 Github的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆