git二:上传代码到github
1.创建上传代码到github的key
在本地创建ssh_key: 在本机执行 ssh-keygen -t rsa -C "你的邮箱"
进入ssh_key保存的目录,可以看到两个key,一个是公钥id_rsa.pub,一个是私钥id_rsa;
将is_rsa.pub公钥的内容copy出来(不能放在记事本)。
在github上添加公钥:登录github,进入settings,进入SSH and GPG keys,点击New SSH key;将公钥的放入key中。
此时,可以在有私钥的电脑上传代码到此github。
在本地测试: ssh -T git@github.com
2.在github上创建远程仓库
start project或New repository,填写仓库名称,选择public和初始化readMe;其它可选。Clone or download,复制仓库地址。
让电脑关联远程仓库: git remote add origin 上面复制的仓库地址
删除关联: git remote rm origin
3.上传代码到github
一、无本地库:
拉取github的仓库: git clone 上面复制的仓库地址
二、有本地库:
上传代码到github之前,要先拉取: git pull origin master
问题:假如拉取失败,提示fatal:refusing to merge unrelated histories,是因为本地和github是两个仓库。
解决:git pull origin master -- allow-unrelated-histories,允许两个仓库有不一样的历史,然后合并即可。
三、上传: git push origin master
4..gitignore:忽略某些文件
创建.gitignore文件: touch .gitignore
posted on 2018-08-12 10:12 myworldworld 阅读(70) 评论(0) 收藏 举报
浙公网安备 33010602011771号