真诚到永远仁者无敌 發表於 2020-4-7 09:04:00

git win10和ubuntu 16.04的安装和配置连接gitee

<h2 id="1-创建gitee仓库">1 创建gitee仓库</h2>
<h3 id="11-登录gitee进入之后点击我的码云-仓库-立即创建">1.1 登录gitee,进入之后点击"我的码云"-&gt;"仓库"-&gt;“立即创建”</h3>
<p><img src="https://img2020.cnblogs.com/blog/1652001/202004/1652001-20200407085211180-2121482009.png" alt="image-20200403152811091" loading="lazy"></p>
<h3 id="12-设置仓库信息点击创建">1.2 设置仓库信息,点击创建</h3>
<p><img src="https://img2020.cnblogs.com/blog/1652001/202004/1652001-20200407085210774-1748611953.png" alt="image-20200403153147687" loading="lazy"></p>
<h2 id="2-win10安装和配置">2 win10安装和配置</h2>
<h3 id="21-下载win10git客户端链接为httpsgitforwindowsorg下载完成后一路next">2.1 下载win10git客户端,链接为:"https://gitforwindows.org/",下载完成后一路“next”</h3>
<p><img src="https://img2020.cnblogs.com/blog/1652001/202004/1652001-20200407085210409-528600443.png" alt="image-20200403093821279" loading="lazy"></p>
<h3 id="22-鼠标右击选择git-bash-打开终端窗口">2.2 鼠标右击选择“Git Bash ”,打开终端窗口</h3>
<p><img src="https://img2020.cnblogs.com/blog/1652001/202004/1652001-20200407085209999-2046821258.png" alt="image-20200403150239447" loading="lazy"></p>
<h3 id="23-配置本地库用户信息">2.3 配置本地库用户信息</h3>
<p>格式:</p>
<pre><code class="language-git">$ git config --global user.name "你的名字或昵称"
$ git config --global user.email "你的邮箱"
</code></pre>
<p>例:</p>
<pre><code class="language-git">$ git config --global user.name "makalo"
$ git config --global user.email "makalochen@foxmail.com"
</code></pre>
<p>如图所示:</p>
<p><img src="https://img2020.cnblogs.com/blog/1652001/202004/1652001-20200407085209709-1726926485.png" alt="image-20200403151858124" loading="lazy"></p>
<h3 id="24-配置ssh-key-免密登录gitee仓库">2.4 配置ssh-key 免密登录gitee仓库</h3>
<h4 id="241-生成ssh公钥">2.4.1 生成ssh公钥</h4>
<pre><code class="language-git">$ ssh-keygen -t rsa -C "xxxxx@xxxxx.com"

# Generating public/private rsa key pair...
# 三次回车即可生成 ssh key
</code></pre>
<h4 id="242-查看你的-public-key并把他添加到码云giteecom-ssh-key添加地址httpsgiteecomprofilesshkeys">2.4.2 查看你的 public key,并把他添加到码云(Gitee.com) SSH key添加地址:https://gitee.com/profile/sshkeys</h4>
<pre><code class="language-git">$ cat ~/.ssh/id_rsa.pub
# ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC6eNtGpNGwstc....
</code></pre>
<p><img src="https://img2020.cnblogs.com/blog/1652001/202004/1652001-20200407085209420-1677480569.png" alt="image-20200403175107138" loading="lazy"></p>
<p>输入key标题和将复制的公钥粘贴到公钥文本框中,点击确定。</p>
<p><img src="https://img2020.cnblogs.com/blog/1652001/202004/1652001-20200407085208998-2098581530.png" alt="image-20200403154936458" loading="lazy"></p>
<h4 id="243-测试是否添加成功">2.4.3 测试是否添加成功</h4>
<p>在本地终端输入</p>
<pre><code class="language-git">$ ssh -T git@gitee.com
</code></pre>
<p>如图则表示添加成功</p>
<p><img src="https://img2020.cnblogs.com/blog/1652001/202004/1652001-20200407085208651-1241728142.png" alt="image-20200403155746333" loading="lazy"></p>
<h3 id="25-下载gitee仓库代码并提交代码">2.5 下载gitee仓库代码并提交代码</h3>
<h4 id="251-下载gitee仓库代码">2.5.1 下载gitee仓库代码</h4>
<p>打开gitee的web下载我们刚刚创建的gitee仓库</p>
<p>点击“我的码云”-&gt;"克隆/下载",找到ssh并复制地址</p>
<p><img src="https://img2020.cnblogs.com/blog/1652001/202004/1652001-20200407085208394-1934291785.png" alt="image-20200403160611520" loading="lazy"></p>
<p><img src="https://img2020.cnblogs.com/blog/1652001/202004/1652001-20200407085207950-279111926.png" alt="image-20200403160659480" loading="lazy"><br>
在终端输入,git clone 命令(类似于SVN 的check out)</p>
<h5 id="下载命令格式">下载命令格式</h5>
<p>格式:</p>
<pre><code class="language-git">$ git clone
</code></pre>
<p>例:</p>
<pre><code class="language-git">$git clone git@gitee.com:makalochen/makalo.git
</code></pre>
<p>输入回车之后,下载成功</p>
<p><img src="https://img2020.cnblogs.com/blog/1652001/202004/1652001-20200407085207585-1421605101.png" alt="image-20200403162650055" loading="lazy"></p>
<h4 id="252-修改并上传">2.5.2 修改并上传</h4>
<h5 id="2521-检查是否关联远程库">2.5.2.1 检查是否关联远程库</h5>
<p><strong>注意:有个.git的隐藏文件夹不要动</strong></p>
<p>找到下载下来的项目(本地库),进入并编辑或创建删除文件</p>
<p><img src="https://img2020.cnblogs.com/blog/1652001/202004/1652001-20200407085207225-280987209.png" alt="image-20200403163817450" loading="lazy"></p>
<p>进入下载的项目路径下,打开命令终端输入</p>
<pre><code class="language-git">$ git remote -v
</code></pre>
<p>查看远程库是否已经关联,下图所示表示已经关联,并且远程库的名字为origin(git 给远程库起的默认名称是 origin,如果有多个远程库,我们需要用不同的名称来标识不同的远程库。)</p>
<p><img src="https://img2020.cnblogs.com/blog/1652001/202004/1652001-20200407085206902-1650371217.png" alt="image-20200403164607197" loading="lazy"></p>
<p>一般clone的库已经关联,如果没有关联可以使用添加关联</p>
<pre><code class="language-git">$ git remote add 远程库名 远程库地址
</code></pre>
<p>进行关联</p>
<h5 id="2522-提交修改">2.5.2.2 提交修改</h5>
<pre><code class="language-git">$ git add . #将当前目录所有文件添加到git暂存区
$ git commit -m "my first commit" #提交并备注提交信息
$ git push origin master #将本地提交推送到远程仓库
</code></pre>
<p>如图表示提交成功</p>
<p><img src="https://img2020.cnblogs.com/blog/1652001/202004/1652001-20200407085206638-363141838.png" alt="image-20200403165843206" loading="lazy"></p>
<h2 id="3-ubuntu1604-安装和配置">3 ubuntu16.04 安装和配置</h2>
<h3 id="31-安装git">3.1 安装git</h3>
<p>以下两个命令,使用root身份依次执行既可安装完成</p>
<pre><code>$ apt-get install libcurl4-gnutls-dev libexpat1-dev gettext \
libz-dev libssl-dev
$ apt-get install git
</code></pre>
<p>安装完成后,使用<code>git --version</code>命令查看版本来确定是否安装成功,如图所示表示安装成功</p>
<p><img src="https://img2020.cnblogs.com/blog/1652001/202004/1652001-20200407085206264-325389945.png" alt="image-20200403172311542" loading="lazy"></p>
<p>接下来的几个步骤:</p>
<p><strong>配置本地库用户信息(2.3)</strong></p>
<p><strong>配置ssh-key 免密登录gitee仓库(2.4)</strong></p>
<p><strong>下载gitee仓库代码并提交代码(2.5)</strong></p>
<p>是跟win10步骤一样的,只不过在配置ssh-key免密登录gitee这个是再生成一个ssk key 相当于是生成两个key一个用于win10,一个用户ubuntu16,04</p>
<p>最后在这里,列一下本文中及git的常用命令:</p>
<p>配置本地库用户信息<br>
$ <strong>git config --global user.name "你的名字或昵称"</strong><br>
$ <strong>git config --global user.email "你的邮箱"</strong></p>
<p>配置ssh-key 免密登录gitee仓库<br>
$ <strong>ssh-keygen -t rsa -C "xxxxx@xxxxx.com"</strong>           #生成ssh key<br>
$ <strong>cat ~/.ssh/id_rsa.pub</strong>                                                                           #查看ssh key 公钥<br>
$ <strong>ssh -T git@gitee.com</strong>                                                                                #测试公钥是否添加成功</p>
<p>下载代码<br>
$ <strong>git clone </strong></p>
<p>关联远程库相关<br>
$ <strong>git remote -v</strong>                                        #查看是否关联<br>
$ <strong>git remote add</strong> 远程库名 远程库地址                        #添加关联远程库<br>
$ <strong>git remote rm 远程库名</strong>                                #删除关联远程库<br>
$ <strong>git remoterename 旧远程库名 新远程库名</strong>            #修改远程库名<br>
$ <strong>git remote set-url 远程库名 远程库地址</strong>                #修改关联远程库地址</p>
<p>提交修改<br>
$ <strong>git add .</strong>                                                #将当前目录所有文件添加到git暂存区<br>
$ <strong>git commit -m "log信息"</strong>                                 #提交并备注提交信息<br>
$ <strong>git push 远程库名(默认为origin) master</strong>             #将本地提交推送到远程仓库</p><br><br>
来源:https://www.cnblogs.com/makalochen/p/12651358.html
頁: [1]
查看完整版本: git win10和ubuntu 16.04的安装和配置连接gitee