git 把一个已经存在的本地仓库提交到服务器仓库

git 把一个已经存在的本地仓库提交到服务器仓库

我有一个本地工程,里面有.git文件,但是没有远程服务器的地址,我在github上新建了一个工程,再不想clone的情况下,我想把本地的工程提交到github的我服务器地址上。具体操作如下

1.打开.git的隐藏文件夹,看到config文件,添加下你远程服务器的地址,如图红色框框内的

[remote "origin"]

url = https://github.com/czl0325/ZLSwipeViewController.git

fetch = +refs/heads/*:refs/remotes/origin/*

[branch "master"]

remote = origin

merge = refs/heads/master



2. git add --all                       提交本地修改到本地仓库

    git commit -m '添加工程'  把本地仓库的commit一下

3. 这时候要先pull远程仓库的内容,git pull origin master   会提示

To https://github.com/czl0325/ZLScrollButtonsView  

! [rejected]        master -> master (non-fast-forward)

error: failed to push some refs to 'https://github.com/czl0325/ZLScrollButtonsView'

hint: Updates were rejected because the tip of your current branch is behind

hint: its remote counterpart. Integrate the remote changes (e.g. hint: 'git pull ...') before pushing again.

hint: See the 'Note about fast-forwards' in 'git push --help' for details.

这是因为你本地仓库的祖先和远程仓库的祖先不一致引起的,请改用 git pull origin master --allow-unrelated-histories 方法来pull, 

pull的时候需要合并,点击i,再按esc,再输入:wq退出即可。

此时如果看到本地仓库已经有了github上的文件,本地库完整的话,请直接执行第五步。

4. 之后在git push origin master,出现错误:

To https://github.com/czl0325/ZLScrollButtonsView

! [rejected]master -> master (non-fast-forward)

error: failed to push some refs to 'https://github.com/czl0325/ZLScrollButtonsView'

hint: Updates were rejected because the tip of your current branch is behind

hint: its remote counterpart. Integrate the remote changes (e.g.

hint: 'git pull ...') before pushing again.

hint: See the 'Note about fast-forwards' in 'git push --help' for details.

需要先执行  git merge --abort  在执行 git reset --merge ,然后再 git pull origin master

5. 此时已经合并了两个仓库了, 执行git push origin master 却失败?我们需要执行  git push -u origin master -f  强制覆盖远程仓库的内容即可




PS:

git 拉取失败。出现LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection

请使用命令 env GIT_SSL_NO_VERIFY=true git clone https://czl@bitbucket.org/czl/seven.git

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 多种多样的工作流使得在项目中实施Git时变得难以选择。这份教程提供了一个出发点,调查企业团队最常见的Git工作流。...
    JSErik阅读 4,483评论 2 8
  • 首先确定电脑安装了git 输入git 会产生提示: 如果没有安装,那么就网上搜索下载完成安装. 可以使用命令行安装...
    彗星来的那一夜阅读 856评论 0 0
  • 2016.12.4 虽然14年开发第一个项目时就已经接触了git,当时xcode已经开始支持git,在github...
    張小明阅读 416评论 1 0
  • 被骗的次数过多,走在路上看到乞讨的孩子或没回家路费的青年人,都不敢再伸出手,条件反射性觉得这又是一场骗局。于是从他...
    xiao徐徐1阅读 244评论 0 1
  • 火焰的顶端 落日的脚下 茫茫黄昏 华美而无上 在秋天的悲哀中成熟 日落大地 大火熊熊 烧红地平线滚滚而来 使人壮烈...
    采兰格格阅读 270评论 0 0