本文记录如何使用github创建项目并上传代码,因为有一段时间没用github了,中途又重装了系统,今天重新安装使用了git。然后特地做简要记录:

1. 创建 SSH Key

SSH Key 默认保存在 C:\Users\Administrator\.ssh 隐藏目录中, id_rsa 和 id_rsa.pub 文件指的是私匙和公匙,如果没有则要新建SSH Key:

 $ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

2. github添加SSH Key

登录github在设置里找到添加SSH Key。打开 id_rsa.pub 文件把全部内容复制到 github 的添加SSH Key里。

3. 创建本地仓库

在本地项目目录下创建仓库,此时本地目录下多了一下.git的隐藏目录:

git init

4. 创建github仓库 / 本地仓库与github仓库同步

创建github项目后,在Clone with SSH取得项目地址,然后就可以与本地仓库建立远程关联:

$ git remote add origin git@github.com:yourgithub/learngit.git

由于github创建项目时,会有创建README和LICENSE文件,而本地没有这些文件,所以要同步github仓库:

git pull origin master

同步github仓库时,如果本地仓库已经有项目代码,还需要消除本地与线上的差异

git pull origin master --allow-unrelated-histories

5. 写代码 / 本地推送到github

git add .
git commit -m "提交说明"
git push origin master

<----    20190613  分割线     ---->

6. 创建分支 / 合并分支

创建并切换新分支:

git checkout -b branchname

新分支推送至github

git push origin branchname

分支push数据

git push --set-upstream origin branchname

在主分支下合并分支,并添加日志记录

git merge branchname --no--ff
git push

<----    20190711  分割线     ---->

7. commit信息的修改

git commit --amend

终端会打开vim编辑器,修改commit信息。在commit已经push的情况下

git push <remote> <branch> -f

强制本地修改覆盖远程仓库

参考文档:

https://git-scm.com/book/zh/v2/%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%B8%8A%E7%9A%84-Git-%E7%94%9F%E6%88%90-SSH-%E5%85%AC%E9%92%A5

https://help.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh

最新文章

  1. [转]Snappy压缩库安装和使用之一
  2. Group Anagrams
  3. php基础知识【函数】(6)mysql数据库
  4. ios7中使用scrollview来横向滑动图片,自动产生偏移竖向的偏移 问题
  5. Entity Framework技巧系列之十四 - Tip 56
  6. 【html5】html5本地简单存储
  7. SSM 使用 mybatis 分页插件 pagehepler 实现分页
  8. 系统右键添加cmd命令
  9. linux 修改配色
  10. .Net外包篇:我是怎么看待外包的(二)
  11. 在windows下安装nvm并管理nodejs版本
  12. 2. springboot启动报错:Field userMapper in com.service.UserService required a bean of type &#39;com.dao.UserMapper&#39; that could not be found.
  13. Java的函数重载必须满足的条件
  14. Java ThreadLocal的使用案例
  15. C语言可变参数个数
  16. BeautifulSoup与Xpath解析库总结
  17. 替换res\drawable中的图片
  18. python中mysql的存储
  19. 随机获取UDID
  20. unity, 如果碰撞使用2d物理,为防止颤动,需将更新position的代码写在FixedUpdate里

热门文章

  1. AI-Info-Micron-Insight:在线购物算法的核心是强大的 DRAM
  2. 信息安全:Token
  3. cassandra根据用户名密码登录cqlsh
  4. u-boot.lds 链接脚本分析(hi3515)
  5. mysql create table
  6. CodeForces 1109F. Sasha and Algorithm of Silence&#39;s Sounds
  7. 2014 SCAU_ACM 暑期集训
  8. switch()出现警告warning:enumeration value ‘xxx’ not handled in switch
  9. mysql由浅入深探究(四)----mysql事务详解
  10. Jsoncpp写“鱘”的json数据,报错。