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
网友评论