一、安装
1、查看是否安装git
<span style="color:#333333"><span style="background-color:#ffffff"><code class="language-perl">rpm -qa|<span style="color:#0000ff">grep</span> git
</code></span></span>
有git加版本号就说明已经安装过了
2、安装git
<span style="color:#333333"><span style="background-color:#ffffff"><code class="language-mipsasm">yum <span style="color:#0000ff">install </span>git
</code></span></span>
3、查看git版本
<span style="color:#333333"><span style="background-color:#ffffff"><code class="language-undefined">git version
</code></span></span>
二、配置git账户
1、配置帐户和密码
<span style="color:#333333"><span style="background-color:#ffffff"><code class="language-verilog">git <span style="color:#0000ff">config</span> --<span style="color:#0000ff">global</span> user<span style="color:#008000">.name</span> <span style="color:#a31515">"Your Name"</span>
git <span style="color:#0000ff">config</span> --<span style="color:#0000ff">global</span> user<span style="color:#008000">.email</span> <span style="color:#a31515">"email@example.com"</span>
</code></span></span>
2、查看配置是否生效
<span style="color:#333333"><span style="background-color:#ffffff"><code class="language-lua">git <span style="color:#0000ff">config</span> <span style="color:#008000">--list</span>
</code></span></span>
三、配置SSH用于拉取远程仓库
1、先在本地生成ssh key,生成公钥和私钥,后续在github等代码托管配置中需要用到
<span style="color:#333333"><span style="background-color:#ffffff"><code class="language-perl">ssh-keygen -t rsa -C <span style="color:#a31515">"your_email@youremail.com"</span>
</code></span></span>
2、确认路径按1次回车,提示:Enter passphrase(输入密码),不用输密码再按2次回车即可。生成的密钥存放路径 /root/.ssh/id_rsa
3、id_rsa:私钥 ,id_rsa.pub:公钥
<span style="color:#333333"><span style="background-color:#ffffff"><code class="language-bash"><span style="color:#0000ff">cat</span> /root/.ssh/id_rsa.pub
</code></span></span>
四、配置github
1、打开 GitHub: Let’s build from here · GitHub
2、New SSH key 添加一个新的ssh key
3、复制刚才生成的 id_rsa.pub 公钥,Add SSH key
其他代码托管如gitlab等类似
五、测试拉github私有项目
1、git clone拉取远程代码,配置了SSH 公/私有项目都是可以拉的,拉取的路径在当前路径
<span style="color:#333333"><span style="background-color:#ffffff"><code class="language-bash">git <span style="color:#0000ff">clone</span> git@github.com:yourname/xxx.git
</code></span></span>