问题1.先创建本地库,后拉取远程仓库时上传失败的问题怎么解决?
操作主要步骤:
step1 设置远程仓库地址:
$ git remote add origin git@gitee.com:yourAccount/reponamexxx.git
step2 推送到远程仓库:
$ git push -u origin "master"
报错信息:
To git@gitee.com:yourAccount/reponamexxx.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'gitee.com:yourAccount/reponamexxx.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 integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
解决办法:
step1 拉取远程仓库,使用 --allow-unrelated-histories选项,本质上是合并(merge):
$ git pull origin master --allow-unrelated-histories
step2:在来一把,不带该选项。
$ git pull origin master
step3:推送
$ git push -u origin "master"
【注】如果是新建本地仓库,没有添加任何文件,只要使用如下语句就可以成功拉取。
$ git pull origin master
问题2:如何在本地用命令行创建一个git仓库,并推送到远程?
操作主要步骤:
在本地用命令行创建一个git仓库,并推送到远程
1. [ git init ]
在gitStore目录下 初始化一个git仓库
2. [ git add . ]
复制一个文件到gitStore目录下,然后执行[ git add . ]将“修改”从当前工作区存放到暂存区
3. [ git commit -m "first commit" ]
将暂存区中存放的文件提交到git仓库
4.在远端新建一个git代码库:https://github.com/*******
5.git remote add origin https://github.com/********
将本地代码库的当前分支与远程的代码库相关联
6.[ git push -u origin master ]
将本地代码库的当前分支推送到远程的代码库