Jimmy小站
小明也有大梦想 — 蒋明/铭首次将本地代码传到github
2019-04-05 / 开发环境配置 / 3088 次围观 / 0 次吐槽github新建repository 将本地代码上传
首先在github上新建repository(具体自行百度,这里以我github账户chase4ever的PLMF项目为例)
其次在当前项目路径 打开cmd输入git init
将本地代码目录变成git项目
然后配置仓库信息
git user.name="jimmy"
git user.email="your_email@126.com"
git remote add https://github.com/chase4ever/PLMF.git
用以下命令生成rsa公钥和密钥,按照提示输入rsa文件存放路径等信息,可以直接回车选择默认值
ssh-keygen -t rsa -C "your_email@126.com"
打开github网站,登录github账号后再settings里面选择新建ssh key,并将刚刚在你本地生成的rsa.pub里的内容复制到网页中的输入框保存(这样,你本地的git就能够获取修改该用户的repository的权限了)
目前为止,github上的远程仓库和你本地的仓库仍然是两个不同的仓库, 因此当你选择add commit,最后push的时候会报错(以我的项目PLMF为例)
To https://github.com/chase4ever/PLMF.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to "https://github.com/chase4ever/PLMF.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.
错误提示说需要先将远程仓库pull,merge到本地仓库先,但是pull的时候依然出错
$ git pull plmf master
warning: no common commits
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From https://github.com/chase4ever/PLMF
* branch master -> FETCH_HEAD
* [new branch] master -> plmf/master
fatal: refusing to merge unrelated histories
错误信息说,存在两个不相关的操作历史,不允许合并,因此陷入僵局。解决办法就是在pull的时候加上一个强制条件,命令如下:
git pull plmf master --allow-unrelated-histories
现在远程和本地仓库就关联成一个,这时可以将本地的代码全部add commit push到远程仓库了
推荐您阅读更多有关于“git,”的文章
本月热文
Copyright © Jimmy小站 Allrights Reserved.备案号:桂ICP备 15005996
额 本文暂时没人评论 来添加一个吧
发表评论