美文网首页GitHub
github and git

github and git

作者: young_xst | 来源:发表于2017-05-03 20:07 被阅读0次

GitHub简介

地址:https://github.com/

主要提供基于git的版本托管服务,全球最大的开源社区。

Goodle:https://github.com/google

苹果:https://github.com/apple

Facebook:https://github.com/facebook

Twitter:https://github.com/twitter

微软:https://github.com/microsoft

Square:https//github.com/square

阿里:https//github.com/alibaba

Linux:https://github.com/torvalds/linux

Rails:https://github.com/rails/rails

Nodejs:https//github.com/node

Swift:https//github.com/swift

CoffeeScript:https//github.com/coffeescript

Ruby:https//github.com/ruby

JakeWharton:https//github.com/JakeWharton

Git

git 是一个版本控制系统,也可以理解成一个工具,跟Java类似

git config --global user.name

git config --global user.email

git init 初始化git仓库

git status 查看当前状态

git add 添加到缓存区

git commit - m 提交

git branch 查看当前分支

git checkout 还原添加到缓存区的文件

git checkout + 分支名 切换分支

git merge + 分支名 将分支合并到当前分支

git branch -d 删除分支

git branch -D 强制删除

git log 查看提交信息

git reset + 提交Id 还原

ssh

提交代码之前一定是需要某种授权的,而github上一般都是基于ssh授权的

ssh是一种网络协议,用于计算机之间的加密登录,大多数Git服务器都会选择使用ssh公钥来进行授权,所以想要在GitHub提交代码的第一步就是要先添加ssh key配置,windows系统安装了git Bash 自带ssh。

输入ssh

 

说明本机已经安装ssh

紧接着输入 ssh-keygen -t rsa。指定rsa算法生成密钥,接着连续输入三个回车键(不需要输入密码),然后生成两个文件 id_rsa 和 id_rsa.pub,id_rsa 是密钥,id_rsa.pub 就是公钥。

接下来将id_rsa.pub的内容添加到GitHub上,这样本地的 id_rsa 密钥跟GitHub上的id_rsa.pub 公钥进行配对,授权成功才可以提交代码。

登录GitHub,在GitHub的设置页面,点击最左侧SSH and GPG keys,点击左上角的 New SSH key 按钮,将id_rsa.pub 文件的内容复制进去,点击 Add SSH key 按钮即可。

SSH key 添加成功后,输入ssh -T git@github.com进行测试,出现下面的提示就成功

 git push origin master 把本地代码推到远程master 分支

 git pull origin master 把远程最新的代码更新到本地

git remote -v 查看当前项目有哪些远程仓库

git stash 把当前分支所有没有commit的代码先暂存起来,这个时候你再执行git status 很干净

git stash list 查看暂存区记录

git stash apply 把暂存区的代码拉回

git stash drop 删除最近一条的stash记录

git stash pop 和apply的区别唯一 区别是,不但会把代码还原,还会自动删除stash记录

git stash clear 清空所有暂存区的记录

相关文章

网友评论

    本文标题:github and git

    本文链接:https://www.haomeiwen.com/subject/erfltxtx.html