[20190611]记录一下github的基本用法
本文记录如何使用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://help.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh
最新文章
- [转]Snappy压缩库安装和使用之一
- Group Anagrams
- php基础知识【函数】(6)mysql数据库
- ios7中使用scrollview来横向滑动图片,自动产生偏移竖向的偏移 问题
- Entity Framework技巧系列之十四 - Tip 56
- 【html5】html5本地简单存储
- SSM 使用 mybatis 分页插件 pagehepler 实现分页
- 系统右键添加cmd命令
- linux 修改配色
- .Net外包篇:我是怎么看待外包的(二)
- 在windows下安装nvm并管理nodejs版本
- 2. springboot启动报错:Field userMapper in com.service.UserService required a bean of type &#39;com.dao.UserMapper&#39; that could not be found.
- Java的函数重载必须满足的条件
- Java ThreadLocal的使用案例
- C语言可变参数个数
- BeautifulSoup与Xpath解析库总结
- 替换res\drawable中的图片
- python中mysql的存储
- 随机获取UDID
- unity, 如果碰撞使用2d物理,为防止颤动,需将更新position的代码写在FixedUpdate里
热门文章
- AI-Info-Micron-Insight:在线购物算法的核心是强大的 DRAM
- 信息安全:Token
- cassandra根据用户名密码登录cqlsh
- u-boot.lds 链接脚本分析(hi3515)
- mysql create table
- CodeForces 1109F. Sasha and Algorithm of Silence&#39;s Sounds
- 2014 SCAU_ACM 暑期集训
- switch()出现警告warning:enumeration value ‘xxx’ not handled in switch
- mysql由浅入深探究(四)----mysql事务详解
- Jsoncpp写“鱘”的json数据,报错。