雨吾双 發表於 2019-9-23 17:25:00

Github使用教程

<p>1、为什么使用GitHub</p>
<p>(1).GitHub的特点</p>
<p>&nbsp; &nbsp;&lt;1&gt;.开源分布式版本管理系统</p>
<p>&nbsp; &nbsp;&lt;2&gt;.开源项目集中的代码库</p>
<p>&nbsp; &nbsp;&lt;3&gt;.所有略有规模的公司都在使用</p>
<p>(2).GitHub的功能介绍</p>
<p>&nbsp; &nbsp;&lt;1&gt;.记录多个版本</p>
<p>&nbsp; &nbsp;&lt;2&gt;.查看历史操作,可以进行版本回退和前进的控制</p>
<p>&nbsp; &nbsp;&lt;3&gt;.多端共享代码,自动合并</p>
<p>(3).GitHub与SVN</p>
<p>&nbsp; &nbsp;&lt;1&gt;.SVN版本集中管理,所有的代码都在中央服务器上</p>
<p>&nbsp; &lt;2&gt;.Git去中心化,每个服务器上都有一个完整的代码库</p>
<p>2.Git客户端安装</p>
<p>&nbsp;&lt;1&gt;.Linux: yum install -y git</p>
<p>&lt;2&gt;.windows:https://git-scm.com/download</p>
<p>&lt;3&gt;mac:brew install git</p>
<p>检查是否安装成功;</p>
<p>git --version</p>
<p>3.GitHub的使用</p>
<p>(1).拥有一个Git账号</p>
<p>&nbsp; 主页:https://github.com</p>
<p>&nbsp; 推荐使用命令行进行操作(git有图形化工具 sourcetree)</p>
<p>(2).配置sshKey</p>
<p>&nbsp; &nbsp;&lt;1&gt;.生成key: ssh-keygen-t rsa -C "邮箱地址"</p>
<p>&nbsp; &nbsp;&lt;2&gt;.cd ~/.ssh(用户目录下的.ssh文件夹)</p>
<p>&nbsp; &nbsp;&lt;3&gt;.复制id_rsa.pub的公钥内容到github网站中(个人账号--&gt;settings--&gt;SSH and GPG keys,New SSH key,弹出SSH keys/Add new 对话框,输入title:任意,key:输入ssh生成的key(id_rsa.pub),点击Add SSH key)</p>
<p>&nbsp;(3).配置多个sshkey</p>
<p>&nbsp; &nbsp;&lt;1&gt;.cd ~/.ssh(windows是用户目录下的.ssh文件夹)</p>
<p>&nbsp; &nbsp;&lt;2&gt;.vim config(新建config文件)</p>
<p>&nbsp; &nbsp;&lt;3&gt;.添加Host/HostName/User/IdentityFile四项</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Host github.com</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;HostName github.com</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;User tanshun1101(github网站上注册的账号)</p>
<p><em id="__mceDel">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;IdentityFile /c/Users/Maxwell/.ssh/id_rsa(要写绝对路径)</em></p>
<p><em><em><em>&nbsp; &lt;4&gt;.配置多个sshkey,只需复制已新增的四项,再补充即可</em></em></em></p>
<p><em><em><em>&nbsp; &nbsp; &nbsp; &nbsp; #个人git</em></em></em></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Host github.com</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;HostName github.com</p>
<p><em id="__mceDel">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;User tanshun1101(github网站上注册的账号)</em></p>
<p><em id="__mceDel">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;IdentityFile /c/Users/Maxwell/.ssh/id_rsa(要写绝对路径)</em></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp;#公司git<em id="__mceDel">&nbsp; &nbsp;&nbsp;</em></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Host github.com (公司git地址)</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;HostName github.com (公司git地址)</p>
<p><em id="__mceDel">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;User tanshun1101(公司github的账号)</em></p>
<p><em id="__mceDel">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;IdentityFile /c/Users/Maxwell/.ssh/id_rsa(要写绝对路径)</em></p>
<p><em>&nbsp; &nbsp;(4).创建git仓库几克隆,拉取和推送操作</em></p>
<p><em>&nbsp; &nbsp;&lt;1&gt;.登陆进入gtthub首页,点击start a project,进入Create a new respository:</em></p>
<p><em>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Owner:github账号,respository name:仓库名称,根据项目命名,使用英文,不能重复</em></p>
<p><em>&nbsp; &nbsp; &nbsp; &nbsp; Description(optional):基于java语言的接口自动化 (简单描述项目)</em></p>
<p><em>&nbsp; &nbsp; &nbsp; &nbsp;public(选择公有的,这样别人可以访问,也可以下载代码,一般选择公有即可)</em></p>
<p><em>&nbsp; &nbsp; &nbsp; private(可以选择让谁看见,需要花钱)</em></p>
<p><em>&nbsp; &nbsp; &nbsp; 点击 create repository</em></p>
<p><em>&nbsp; &lt;2&gt;.克隆仓库:</em></p>
<p><em>&nbsp; &nbsp; &nbsp; &nbsp; 进入github项目中,复制https:https://github.com/tanshun1101/AutoTest2.git</em></p>
<p><em>&nbsp; &nbsp; &nbsp; &nbsp; 进入git的workspace目录下,创建文件夹: mkdir Interface Test,并进入Interface-Test</em></p>
<p><em>&nbsp; &nbsp; &nbsp; &nbsp;使用git 命令:git clone&nbsp;https://github.com/tanshun1101/AutoTest2.git 回车,会把仓库克隆到本地</em></p>
<p><em>&lt;3&gt;.本地文件推送到github:</em></p>
<p><em>&nbsp; &nbsp; &nbsp; &nbsp;cd&nbsp;<em>AutoTest2(进入仓库)</em></em></p>
<p><em>&nbsp; &nbsp; &nbsp; vim test.txt</em></p>
<p><em>&nbsp; &nbsp; &nbsp; 输入内容:111111111,保存退出</em></p>
<p><em>&nbsp; &nbsp; &nbsp;如何将文件推送到github?</em></p>
<p><em>&nbsp; &nbsp; &nbsp;git status命令可以查看仓库里面本地文件的状态</em></p>
<p><em><em>&nbsp; &nbsp; &nbsp;<img src="https://img2018.cnblogs.com/blog/1411863/201909/1411863-20190923162512295-1338597623.png"></em></em></p>
<p>&nbsp;</p>
<p>&nbsp; &nbsp; &nbsp;提示可以使用git add file 命令去追踪</p>
<p><em id="__mceDel"><em>&nbsp; &nbsp; &nbsp;输入$ git add test.txt 回车,如果出现:</em></em></p>
<p><em id="__mceDel"></em><em id="__mceDel">&nbsp; &nbsp; &nbsp;warning: LF will be replaced by CRLF in test.txt.</em></p>
<p><em id="__mceDel">&nbsp; &nbsp; The file will have its original line endings in your working directory</em><em id="__mceDel"><em>&nbsp; &nbsp;</em></em></p>
<p>&nbsp; &nbsp; 原来是Git默认配置替换回车换行成统一的CRLF,我们只需要修改配置禁用该功能即可。</p>
<p>&nbsp; &nbsp;Gitshell中输入如下命令解决:</p>
<p>&nbsp; &nbsp;git config --global&nbsp;core.autocrlf false</p>
<p><em>&nbsp; &nbsp;继续使用git add 命令</em></p>
<p><em>&nbsp; &nbsp;git add test.txt 回车</em></p>
<p><em>&nbsp; &nbsp;<img src="https://img2018.cnblogs.com/blog/1411863/201909/1411863-20190923165432216-304039263.png"></em></p>
<p>&nbsp;</p>
<p>&nbsp; &nbsp;再次使用git status 查看,发现文件已经追踪了</p>
<p>&nbsp; &nbsp;继续在gitbash中输入:<em id="__mceDel">git commit -m "增加测试文件" (加上注释说明,不是必须)</em></p>
<p><em>&nbsp; &nbsp;继续在gitbash中输入:git push (即可以将文件推送到远程github)</em></p>
<p><em>&nbsp;<img src="https://img2018.cnblogs.com/blog/1411863/201909/1411863-20190923165941868-59722522.png"></em></p>
<p>&nbsp;</p>
<p>&nbsp;如果在push过程中提示需要输入账号密码,解决办法是:</p>
<p>1)在个人电脑的用户目录创建一个文本文件,名为.git-credentials,关于用户目录:</p>
<p>a、windows:C/Users/username</p>
<p>b、mac:/Users/username</p>
<p>c、Linux:/home/username</p>
<p>2)向.git-credentials文件中添加一下内容:</p>
<p>https:{username}:{password}@github.com</p>
<p>3)修改git配置</p>
<p>a、执行命令 git config --global credential.helper store<br>重新push即可</p>
<p>进入github网站,个人项目中,发现文件已经上传至github了</p>
<p>拉取代码 git pull(从github上拉取代码到本地):</p>
<p><img src="https://img2018.cnblogs.com/blog/1411863/201909/1411863-20190923172353926-2142647548.png"></p>
<p>&nbsp;</p>
<p>&nbsp;以上是git基本命令</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><em>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</em></p>
<p><em>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</em></p><br><br>
来源:https://www.cnblogs.com/maxwellsky/p/11573545.html
頁: [1]
查看完整版本: Github使用教程