GitHub是一个开源的大仓库,咱们常常从github上下载项目进行学习和研究,下面是一个完整的步骤——往GitHub上传一个新项目。javascript
一、注册GitHub帐号,地址:https://github.com
php
二、登陆:java
三、登陆以后的页面,是咱们star其余人的一些信息,相似于QQ空间的好友状态git
一、查看系统中是否配置过SSH keys,并处理github
1.1 终端里输入显示隐藏文件:shell
defaults write com.apple.finder AppleShowAllFiles -bool true
输入命令完成以后须要重启Finder 桌面顶部苹果logo->强制退出->
就可显示隐藏文件。ruby
还有一种方法,使用命令:cd ~/.ssh 检查是否已经存在sshbash
1.2 而后前往我的文件查看有没有 .ssh 文件夹,有的话我的建议删除掉,重新配置app
二、在本地配置SSH keydom
建立一个 .ssh 文件夹 命令:mkdir .ssh
gonganxinxideiMac-2:.ssh gonganxinxi$ mkdir .ssh
进入刚建立的 .ssh文件夹目录里 命令:cd .ssh
gonganxinxideiMac-2:.ssh gonganxinxi$ cd .ssh
命令:ssh-Keygen -t rsa -C “youEmail”,输入完成以后一直按回车键 中间会提示你要输入文件、密码,不用管一直按回车直到出现下面这样。
gonganxinxideiMac-2:.ssh gonganxinxi$ ssh-Keygen -t rsa -C “385584895@qq.com” Generating public/private rsa key pair. Enter file in which to save the key (/Users/gonganxinxi/.ssh/id_rsa): Created directory '/Users/gonganxinxi/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /Users/gonganxinxi/.ssh/id_rsa. Your public key has been saved in /Users/gonganxinxi/.ssh/id_rsa.pub. The key fingerprint is: SHA256:2UDch+eu01e0XGA89tE89Kpnmdk+SlTLtxijRHaIX9w “385584895@qq.com” The key's randomart image is: +---[RSA 2048]----+ | ... . ..o.| | .. + = Bo+| | .. B * E+| | ++ + o.=| | S .+ +o++| | . +.+B+| | +.o*o.| | o oo.o | | . o. o| +----[SHA256]-----+
指令:ls -la 查看 若是输出相似这样的信息,就说明配置成功
gonganxinxideiMac-2:.ssh gonganxinxi$ ls -la total 0 drwxr-xr-x 2 gonganxinxi staff 68 9 1 16:50 . drwx------ 6 gonganxinxi staff 204 9 1 16:50 ..
到目前这步应该不会有什么问题,咱们继续。
拷贝SSH key,会在github上进行配置的时候使用
gonganxinxideiMac-2:.ssh gonganxinxi$ pbcopy < ~/.ssh/id_rsa.pub
三、在github配置SSH key
3.1 找到SSH key配置位置
3.2 填写SSH key配置信息
此处将在终端上使用命令pbcopy < ~/.ssh/id_rsa.pub拷贝的信息粘贴到4
位置,而后Add SSH key就添加完成了。
如图
四、回到终端,进行SSH确认链接
输入命令:ssh -T Git@github.com
执行完这条指令以后会输出 Are you sure you want to continue connecting (yes/no)? 输入 yes 回车
回到github,刷新网页就能够看到钥匙旁的灰色小圆点变绿,就代表已经添加成功了。此时github上面的SSH key 456会变成和123同样的绿色。(若是 网速慢,可能要稍等一会)
固然也有可能出现这样的问题:
gonganxinxideiMac-2:.ssh gonganxinxi$ ssh -T Git@github.com The authenticity of host 'github.com (192.30.253.112)' can't be established. RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8. Are you sure you want to continue connecting (yes/no)? yes
此时即便输入yes
Warning: Permanently added 'github.com,192.30.253.112' (RSA) to the list of known hosts. Permission denied (publicly).
这个问题查了许久,发现是由于有时候防火墙会拒绝 SSH链接(Sometimes, firewalls refuse to allow SSH connections entirely. )在github的帮助中能够看到该问题。他们也给出了解决方案https://help.github.com/articles/using-ssh-over-the-https-port/
经过命令:ssh -T -p 443 git@ssh.github.com使用克隆过的SSH链接HTTPS端口。
gonganxinxideiMac-2:.ssh gonganxinxi$ ssh -T -p 443 git@ssh.github.com The authenticity of host '[ssh.github.com]:443 ([192.30.253.123]:443)' can't be established. RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '[ssh.github.com]:443,[192.30.253.123]:443' (RSA) to the list of known hosts. Hi zhangyanxiao! You've successfully authenticated, but GitHub does not provide shell access.
看见You’ve successfully authenticated, but GitHub does not provide shell access 。这就表示已成功连上github。
成功啦,棒棒哒!!!
下面能够在github建立仓库,上传项目了
一、建立github远程仓库
仓库建立完成后如图
二、建立git本地仓库
咱们须要设置username和email,由于github每次commit都会记录他们。
git config --global user.name "github的用户名" git config --global user.email"注册邮箱名"
cd到你的本地项目、根目录下,再执行git命令
gonganxinxideiMac-2:.ssh gonganxinxi$ cd /Users/gonganxinxi/Desktop/HexTurnRGB——Demo
git本地仓库初始化,这个时候能够在咱们的项目文件中看到.git文件夹了
gonganxinxideiMac-2:HexTurnRGB——Demo gonganxinxi$ git init Initialized empty Git repository in /Users/gonganxinxi/Desktop/HexTurnRGB——Demo/.git/
将本地项目的全部文件添加到暂存区中
gonganxinxideiMac-2:HexTurnRGB——Demo gonganxinxi$ git add .
将暂存区的文件提交到git本地仓库
命令:git commit -m "第一次提交" 双引号里面写注释语句
会出现不少如图,下面还有,没截进去。。。。
三、将git本地仓库和Github远程仓库关联
在github中打开要上传项目的远程仓库,获得网址
https://github.com/zhangyanxiao/HexTurnRGB
将本地仓库关联到Github上,后面的URL地址就是刚刚复制的github上仓库的https地址
gonganxinxideiMac-2:HexTurnRGB——Demo gonganxinxi$ git remote add origin https://github.com/zhangyanxiao/HexTurnRGB
从远程仓库pull,获取远程仓库的文件到本地仓库(往GitHub上提交东西的时候,会由于远程上有东西更新了可是本地仓库没有更新而形成提交失败,因此咱们在push以前,都会pull一遍)
gonganxinxideiMac-2:HexTurnRGB——Demo gonganxinxi$ git pull origin master
会出现如下界面:在这里面能够写pull的缘由注释。用法可参照cocoapods导入第三方库的使用。
最后一步,将代码由本地仓库上传到Github远程仓库(此处,可能咱们会查看当前是否在master,使用命令:git check master)
gonganxinxideiMac-2:HexTurnRGB——Demo gonganxinxi$ git push -u origin master
哈哈,完成了呢,看图,快👀图👀图
最后分享一些Github经常使用的命令: 切换分支:git checkout name 撤销修改:git checkout -- file 删除文件:git rm file 查看状态:git status 添加记录:git add file 或 git add . 添加描述:git commit -m "miao shu nei rong" 同步数据:git pull 提交数据:git push origin name 分支操做 查看分支:git branch 建立分支:git branch name 切换分支:git checkout name 建立+切换分支:git checkout -b name 合并某分支到当前分支:git merge name 删除分支:git branch -d name 删除远程分支:git push origin :name