你卡了 發表於 2025-2-21 15:51:00

配置 gitee

<p>配置 git 连接 gitee.com&nbsp; 【可行】</p>
<p><br>在配置Git仓库以便使用Gitee(中国的一个代码托管平台)时,你需要遵循以下步骤:<br><strong>1. 安装Git</strong><br>确保你的计算机上已经安装了Git。你可以从Git官网&nbsp;&nbsp; https://git-scm.com/ &nbsp; 下载并安装Git。</p>
<p>安装步骤 请看:&nbsp;https://www.cnblogs.com/emanlee/p/16296704.html</p>
<p><br><strong>2. 配置Git用户信息</strong><br>打开命令行工具(如 <strong>cmd</strong>、Terminal等),配置你的Git用户信息。这是为了在提交代码时标识你的身份。</p>
<p><span style="background-color: rgba(255, 255, 0, 1)">下面的用户名和邮箱,要和 gitee(或 github)上注册用的一模一样才行</span><br><span style="background-color: rgba(255, 255, 0, 1)">git config --global user.name "你的用户名"</span><br><span style="background-color: rgba(255, 255, 0, 1)">git config --global user.email "你的邮箱"</span></p>
<p>说明:用户名中<strong>不要</strong>有中文和特殊符号(如 @,#,% 等)。</p>
<p><br><strong>3. 生成SSH密钥</strong><br>为了能够安全地与Gitee进行通信,你需要生成一个SSH密钥对。<br><br>首先检查是否已存在SSH密钥:<br><strong>ls -al ~/.ssh</strong></p>
<div class="cnblogs_code">
<pre>$ <span style="color: rgba(0, 0, 255, 1)">ls</span> -al ~/.<span style="color: rgba(0, 0, 255, 1)">ssh</span><span style="color: rgba(0, 0, 0, 1)">
total </span><span style="color: rgba(128, 0, 128, 1)">79</span><span style="color: rgba(0, 0, 0, 1)">
drwxr</span>-xr-x <span style="color: rgba(128, 0, 128, 1)">1</span> Administrator <span style="color: rgba(128, 0, 128, 1)">197121</span>    <span style="color: rgba(128, 0, 128, 1)">0</span>3月 <span style="color: rgba(128, 0, 128, 1)">18</span><span style="color: rgba(128, 0, 128, 1)">2024</span>./<span style="color: rgba(0, 0, 0, 1)">
drwxr</span>-xr-x <span style="color: rgba(128, 0, 128, 1)">1</span> Administrator <span style="color: rgba(128, 0, 128, 1)">197121</span>    <span style="color: rgba(128, 0, 128, 1)">0</span>2月 <span style="color: rgba(128, 0, 128, 1)">21</span> <span style="color: rgba(128, 0, 128, 1)">07</span>:<span style="color: rgba(128, 0, 128, 1)">41</span>../
-rw-r--r-- <span style="color: rgba(128, 0, 128, 1)">1</span> Administrator <span style="color: rgba(128, 0, 128, 1)">197121</span> <span style="color: rgba(128, 0, 128, 1)">2602</span>5月<span style="color: rgba(128, 0, 128, 1)">5</span><span style="color: rgba(128, 0, 128, 1)">2021</span><span style="color: rgba(0, 0, 0, 1)">id_rsa
</span>-rw-r--r-- <span style="color: rgba(128, 0, 128, 1)">1</span> Administrator <span style="color: rgba(128, 0, 128, 1)">197121</span><span style="color: rgba(128, 0, 128, 1)">569</span>5月<span style="color: rgba(128, 0, 128, 1)">5</span><span style="color: rgba(128, 0, 128, 1)">2021</span> <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">id_rsa - Copy.pub.txt</span><span style="color: rgba(128, 0, 0, 1)">'</span>
-rw-r--r-- <span style="color: rgba(128, 0, 128, 1)">1</span> Administrator <span style="color: rgba(128, 0, 128, 1)">197121</span><span style="color: rgba(128, 0, 128, 1)">569</span>5月<span style="color: rgba(128, 0, 128, 1)">5</span><span style="color: rgba(128, 0, 128, 1)">2021</span><span style="background-color: rgba(255, 255, 0, 1)"><strong><span style="color: rgba(0, 0, 0, 1)">id_rsa.pub
</span></strong></span>-rw-r--r-- <span style="color: rgba(128, 0, 128, 1)">1</span> Administrator <span style="color: rgba(128, 0, 128, 1)">197121</span><span style="color: rgba(128, 0, 128, 1)">472</span>3月 <span style="color: rgba(128, 0, 128, 1)">18</span><span style="color: rgba(128, 0, 128, 1)">2024</span><span style="color: rgba(0, 0, 0, 1)">known_hosts
</span>-rw-r--r-- <span style="color: rgba(128, 0, 128, 1)">1</span> Administrator <span style="color: rgba(128, 0, 128, 1)">197121</span><span style="color: rgba(128, 0, 128, 1)">289</span>3月 <span style="color: rgba(128, 0, 128, 1)">18</span><span style="color: rgba(128, 0, 128, 1)">2024</span>known_hosts.old</pre>
</div>
<p>&nbsp;</p>
<p>如果不存在,生成新的SSH密钥:</p>
<p><span style="background-color: rgba(255, 255, 0, 1)">下面的 邮箱,要和 gitee(或 github)上注册用的一模一样才行</span><br><strong>ssh-keygen -t rsa -C "你的邮箱"</strong></p>
<p>按照提示操作,你可以选择直接按回车键接受默认的文件保存位置(如~/.ssh/id_rsa),也可以为你的密钥设置一个安全的密码。</p>
<p><br><strong>4. 添加SSH密钥到Gitee</strong><br>&nbsp;&nbsp;&nbsp; 打开Gitee网站,登录你的账号。<br>&nbsp;&nbsp;&nbsp; 进入<strong>“设置”-&gt;“安全设置”-&gt;“SSH公钥”</strong>。<br>&nbsp;&nbsp;&nbsp; <strong>点击“新增公钥”,将第3步中生成的公钥(~/.ssh/<span style="background-color: rgba(255, 255, 0, 1)">id_rsa.pub</span>文件中的内容)复制粘贴到输入框中。</strong><br>&nbsp;&nbsp;&nbsp; 点击“确定”保存。<br><br><strong>5. 测试SSH连接</strong><br>在命令行中,执行以下命令以测试SSH连接是否成功:<br>ssh -T git@gitee.com<br>如果一切配置正确,你会看到类似“Hi 用户名! You've successfully authenticated, but GITEE.COM does not provide shell access.”的提示。</p>
<p>&nbsp;</p>
<p><br><strong>6. 克隆或创建仓库</strong><br>现在你可以通过SSH方式克隆仓库或创建一个新的仓库了。例如,克隆一个仓库(前提是已经在gitee.com中创建了仓库):<br>git clone git@gitee.com:用户名/仓库名.git</p>
<p>如果执行上面命令出现错误,可以在 windows 的命令行窗口执行(CMD),不在 git bash窗口执行。<br><br><strong>7. 推送代码到Gitee(初次推送)</strong><br>如果你已经克隆了一个仓库,并且想要推送代码到Gitee,你需要设置远程仓库的URL:<br>git remote set-url origin git@gitee.com:用户名/仓库名.git<br><br>然后,你可以添加并推送你的更改:<br><br>git add .<br>git commit -m "提交信息"<br>git push -u origin master&nbsp; # 或其他分支名,如main等<br><br>按照这些步骤,你应该能够成功配置并使用Gitee进行Git操作。</p>
<p>&nbsp;</p><br><br>
来源:https://www.cnblogs.com/emanlee/p/18729324
頁: [1]
查看完整版本: 配置 gitee