美文网首页
git 把一个已经存在的本地仓库提交到服务器仓库

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

作者: 厦门第一帅哥 | 来源:发表于2017-11-03 17:08 被阅读161次

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 把一个已经存在的本地仓库提交到服务器仓库 我有一个本地工程,里面有.git文件,但是没有远程服务器的地址,...

  • Git 上传文件命令

    git添加到本地仓库 git提交到本地仓库 git推送到远程仓库 git合并分支 当前配置链接命令 把当前地址设置...

  • Git 基础操作

    远程仓库 : 源码文件存在的服务器本地仓库 : 本地的项目git仓库URL : 远程仓库的地址remote : ...

  • Git常用命令

    1、初始化本地git仓库 git init 2、添加文件到本地git仓库 git add . 3、提交到本地仓库 ...

  • git管理

    进入git仓库cd ~/.ssh 把文件添加到本地库git add . 把文件修改提交到仓库git commit ...

  • Git常用命令笔记

    git命令使用 1 创建远程仓库(初始化--提交到本地仓库--提交到远程仓库) $ git init ...

  • 4、git

    一、为本地仓库设置远程仓库 1、建立好本地仓库,git init,git add .等操作,将代码提交到本地仓库 ...

  • git

    git 如果服务器上没有本地代码git仓库,先在服务器建立1个git仓库,然后在本地git仓库增加服务器仓库URL...

  • Git命令

    git push 作用:将本地仓库中代码提交到远程仓库 语法 :git push 仓库地址 master git ...

  • GIT简单使用

    本地配置全局git 创建本地仓库提交到git上 该针对本地没有存在的项目。 提交本地已存在的项目到git 针对本地...

网友评论

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

      本文链接:https://www.haomeiwen.com/subject/mkntmxtx.html