神奇大自然 發表於 2025-12-16 15:20:00

完整教程:Gitee完全新手教程

<style>pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", monospace !important; font-size: 14px !important; line-height: 1.6 !important; padding: 16px !important; margin: 16px 0 !important; background-color: rgba(248, 248, 248, 1) !important; border: 1px solid rgba(225, 228, 232, 1) !important; border-radius: 6px !important; tab-size: 4 !important; -moz-tab-size: 4 !important; max-width: 100% !important; box-sizing: border-box !important }
code { font-family: "Consolas", "Monaco", "Courier New", monospace !important; font-size: 14px !important; white-space: pre !important; word-wrap: normal !important; word-break: normal !important; overflow-wrap: normal !important; display: inline !important; background: rgba(0, 0, 0, 0) !important; border: none !important; padding: 0 !important; margin: 0 !important; line-height: inherit !important }
pre code { background: rgba(0, 0, 0, 0) !important; border: 0 !important; border-radius: 0 !important; display: block !important; line-height: 1.6 !important; margin: 0 !important; max-width: none !important; overflow: visible !important; padding: 0 !important; white-space: pre !important; word-wrap: normal !important; word-break: normal !important; color: inherit !important }
.token.comment, .token.prolog, .token.doctype, .token.cdata { color: rgba(112, 128, 144, 1) !important; font-style: italic !important }
.token.punctuation { color: rgba(153, 153, 153, 1) !important }
.token.atrule, .token.attr-value, .token.keyword { color: rgba(0, 119, 170, 1) !important; font-weight: bold !important }
.token.function, .token.class-name { color: rgba(221, 74, 104, 1) !important; font-weight: bold !important }
.token.selector, .token.attr-name, .token.string, .token.char, .token.builtin, .token.inserted { color: rgba(102, 153, 0, 1) !important }
.token.property, .token.tag, .token.boolean, .token.number, .token.constant, .token.symbol, .token.deleted { color: rgba(153, 0, 85, 1) !important }
.cnblogs-markdown pre, .cnblogs-post-body pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; background-color: rgba(248, 248, 248, 1) !important; border: 1px solid rgba(225, 228, 232, 1) !important; border-radius: 6px !important; padding: 16px !important; margin: 16px 0 !important }
pre, pre, pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important }</style>
      <div class="markdown_views prism-atom-one-dark" id="content_views"><svg style="display: none" xmlns="http://www.w3.org/2000/svg"><path d="M5,0 0,2.5 5,5z" id="raphael-marker-block" stroke-linecap="round" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0)"></path></svg><p></p><div class="toc"><h4>文章目录</h4><ul><li><ul><li> Gitee完全新手教程</li><li><ul><li>一、注册与准备</li><li>二、创建第一个仓库(详细步骤)</li><li><ul><li>步骤1:点击创建按钮</li><li>步骤2:填写基础信息</li><li>步骤3:关键设置</li><li>步骤4:创建完成</li></ul></li><li>三、本地操作指南</li><li><ul><li>1. 克隆仓库到本地</li><li>2. 日常工作流程</li><li>3. 常用命令总结</li></ul></li><li>四、重要概念解释</li><li><ul><li>1. 仓库(Repository)</li><li>2. 分支(Branch)</li><li>3. 提交(Commit)</li><li>4. 推送(Push)和拉取(Pull)</li></ul></li><li>五、新手注意事项 ⚠️</li><li><ul><li> 绝对不要做</li><li>✅ 推荐做法</li></ul></li><li>六、.gitignore模板示例</li><li>七、遇到问题怎么办?</li><li><ul><li>常见问题解决</li></ul></li><li>八、学习路径建议</li><li>九、第1周详细学习计划:掌握基础操作</li><li><ul><li>每日练习任务</li></ul></li><li>十、第2周学习计划:查看与比较</li><li><ul><li>核心技能培养</li></ul></li><li>十一、第3周学习计划:冲突解决</li><li><ul><li>冲突处理训练</li></ul></li><li>十二、第4周学习计划:分支管理</li><li><ul><li>分支操作全面掌握</li></ul></li><li>十三、进阶学习建议</li><li><ul><li>完成基础学习后的方向</li><li>持续学习资源</li></ul></li></ul></li></ul></li></ul></div><p></p><h3> Gitee完全新手教程</h3><h4>一、注册与准备</h4><ol><li><p><strong>注册账号</strong></p><ul><li>访问 gitee.com</li><li>使用手机号或邮箱注册</li><li>完善个人资料(用户名很重要,会出现在仓库地址中)</li></ul></li><li><p><strong>安装Git</strong></p><ul><li>Windows: 下载 Git Bash</li><li>Mac: 使用 Homebrew <code>brew install git</code></li><li>Linux: <code>sudo apt-get install git</code></li></ul></li><li><p><strong>配置本地Git</strong></p> <pre style="white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important"><code class="prism language-bash"><span class="token function">git</span> config --global user.name <span class="token string">"你的用户名"</span>
<span class="token function">git</span> config --global user.email <span class="token string">"你的邮箱"</span></code></pre> </li></ol><h4>二、创建第一个仓库(详细步骤)</h4><h5>步骤1:点击创建按钮</h5><ul><li>在Gitee首页点击右上角 <strong>+</strong> → <strong>新建仓库</strong></li></ul><h5>步骤2:填写基础信息</h5><ul><li><strong>仓库名称</strong>: 例如 <code>learning-python</code></li><li><strong>路径</strong>: 自动生成,保持与仓库名一致</li><li><strong>介绍</strong>: 简单描述,如"我的Python学习笔记"</li></ul><h5>步骤3:关键设置</h5><ul><li>✅ <strong>初始化仓库</strong></li><li>✅ <strong>设置模板</strong> → 只选 <strong>Readme文件</strong></li><li>❌ <strong>分支模型</strong> → 不选</li><li>✅ <strong>.gitignore</strong> → 选择你学习的语言</li><li>✅ <strong>开源许可证</strong> → 选择 <strong>MIT License</strong></li></ul><h5>步骤4:创建完成</h5><p>点击"创建"按钮,你的第一个仓库就诞生了!</p><h4>三、本地操作指南</h4><h5>1. 克隆仓库到本地</h5>
<pre style="white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important"><code class="prism language-bash"><span class="token function">git</span> clone https://gitee.com/你的用户名/仓库名.git
<span class="token builtin class-name">cd</span> 仓库名</code></pre>
<h5>2. 日常工作流程</h5>
<pre style="white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important"><code class="prism language-bash"><span class="token comment"># 1. 添加文件后</span>
<span class="token function">git</span> <span class="token function">add</span> <span class="token builtin class-name">.</span>
<span class="token comment"># 2. 提交更改</span>
<span class="token function">git</span> commit -m <span class="token string">"描述这次提交的内容"</span>
<span class="token comment"># 3. 推送到Gitee</span>
<span class="token function">git</span> push origin master</code></pre>
<h5>3. 常用命令总结</h5>
<pre style="white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important"><code class="prism language-bash"><span class="token comment"># 查看状态</span>
<span class="token function">git</span> status
<span class="token comment"># 查看提交历史</span>
<span class="token function">git</span> log
<span class="token comment"># 拉取远程更新</span>
<span class="token function">git</span> pull
<span class="token comment"># 查看文件差异</span>
<span class="token function">git</span> <span class="token function">diff</span></code></pre>
<h4>四、重要概念解释</h4><h5>1. 仓库(Repository)</h5><ul><li>就是你的项目文件夹,包含所有代码和历史记录</li></ul><h5>2. 分支(Branch)</h5><ul><li>主分支:通常叫 <code>master</code> 或 <code>main</code></li><li>功能分支:开发新功能时创建的分支</li><li><strong>新手建议</strong>: 先在主分支上练习,熟练后再学习分支管理</li></ul><h5>3. 提交(Commit)</h5><ul><li>每次提交都是一次"存档",记录了你做了哪些修改</li><li>提交信息要写清楚,方便以后回顾</li></ul><h5>4. 推送(Push)和拉取(Pull)</h5><ul><li>Push: 将本地更改上传到Gitee</li><li>Pull: 将Gitee上的更新下载到本地</li></ul><h4>五、新手注意事项 ⚠️</h4><h5> 绝对不要做</h5><ol><li><p><strong>不要提交大文件</strong>(超过100MB)</p><ul><li>会影响仓库性能</li><li>解决方案:使用<code>.gitignore</code>过滤</li></ul></li><li><p><strong>不要直接在主分支上做危险实验</strong></p><ul><li>可以先创建测试分支</li><li>或者本地备份后再操作</li></ul></li><li><p><strong>不要提交敏感信息</strong></p><ul><li>密码、API密钥、配置文件等</li><li>一旦提交很难彻底删除</li></ul></li></ol><h5>✅ 推荐做法</h5><ol><li><p><strong>勤提交,少推送</strong></p><ul><li>本地可以频繁commit</li><li>完成一个功能后再push</li></ul></li><li><p><strong>写好提交信息</strong></p><ul><li>坏例子: <code>git commit -m "修复"</code></li><li>好例子: <code>git commit -m "修复用户登录时的密码验证bug"</code></li></ul></li><li><p><strong>定期同步</strong></p><ul><li>开始工作前先 <code>git pull</code></li><li>避免合并冲突</li></ul></li></ol><h4>六、.gitignore模板示例</h4><p>根据你的学习方向选择:</p><p><strong>Python学习</strong></p>
<pre style="white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important"><code># 虚拟环境
venv/
.env/
# 缓存文件
__pycache__/
*.pyc
# IDE配置
.vscode/
.idea/</code></pre>
<p><strong>前端学习</strong></p>
<pre style="white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important"><code># 依赖目录
node_modules/
dist/
# 日志文件
*.log
npm-debug.log*</code></pre>
<h4>七、遇到问题怎么办?</h4><h5>常见问题解决</h5><ol><li><p><strong>推送被拒绝</strong></p><ul><li>先执行 <code>git pull --rebase origin master</code></li><li>然后再 <code>git push</code></li></ul></li><li><p><strong>提交了错误文件</strong></p> <pre style="white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important"><code class="prism language-bash"><span class="token comment"># 撤销上次提交</span>
<span class="token function">git</span> reset --soft HEAD~1
<span class="token comment"># 然后重新提交</span></code></pre> </li><li><p><strong>忘记提交某些文件</strong></p> <pre style="white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important"><code class="prism language-bash"><span class="token function">git</span> <span class="token function">add</span> 漏掉的文件
<span class="token function">git</span> commit --amend<span class="token comment"># 合并到上次提交</span></code></pre> </li></ol><h4>八、学习路径建议</h4><ol><li>熟悉基本操作(clone, add, commit, push)</li><li>学习查看历史记录和文件差异</li><li>练习解决简单冲突</li><li>尝试创建和使用分支</li></ol><h4>九、第1周详细学习计划:掌握基础操作</h4><h5>每日练习任务</h5><p><strong>周一:环境搭建</strong></p><ul><li>完成Gitee账号注册</li><li>安装并配置Git</li><li>创建第一个测试仓库</li></ul><p><strong>周二:本地仓库操作</strong></p>
<pre style="white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important"><code class="prism language-bash"><span class="token comment"># 创建学习目录</span>
<span class="token function">mkdir</span> gitee-learning
<span class="token builtin class-name">cd</span> gitee-learning
<span class="token comment"># 初始化本地仓库</span>
<span class="token function">git</span> init
<span class="token comment"># 创建第一个文件</span>
<span class="token builtin class-name">echo</span> <span class="token string">"# 我的学习笔记"</span> <span class="token operator">&gt;</span> README.md
<span class="token function">git</span> <span class="token function">add</span> README.md
<span class="token function">git</span> commit -m <span class="token string">"添加README文件"</span></code></pre>
<p><strong>周三:连接远程仓库</strong></p><ul><li>在Gitee创建名为<code>gitee-practice</code>的仓库</li><li>将本地仓库与远程关联</li></ul>
<pre style="white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important"><code class="prism language-bash"><span class="token function">git</span> remote <span class="token function">add</span> origin https://gitee.com/你的用户名/gitee-practice.git
<span class="token function">git</span> push -u origin master</code></pre>
<p><strong>周四:日常工作流练习</strong></p><ul><li>修改README文件</li><li>添加新的学习笔记文件</li><li>完成一次完整的add→commit→push流程</li></ul><p><strong>周五:复习巩固</strong></p><ul><li>回顾本周所有操作</li><li>尝试在不同电脑上克隆仓库并操作</li><li>总结遇到的问题和解决方案</li></ul><h4>十、第2周学习计划:查看与比较</h4><h5>核心技能培养</h5><p><strong>周一:学习查看状态和历史</strong></p>
<pre style="white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important"><code class="prism language-bash"><span class="token comment"># 查看当前状态</span>
<span class="token function">git</span> status
<span class="token comment"># 查看详细提交历史</span>
<span class="token function">git</span> log --oneline --graph
<span class="token comment"># 查看特定文件的修改历史</span>
<span class="token function">git</span> log -p filename</code></pre>
<p><strong>周二:文件差异比较</strong></p>
<pre style="white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important"><code class="prism language-bash"><span class="token comment"># 比较工作区与暂存区的差异</span>
<span class="token function">git</span> <span class="token function">diff</span>
<span class="token comment"># 比较暂存区与最新提交的差异</span>
<span class="token function">git</span> <span class="token function">diff</span> --staged
<span class="token comment"># 比较两个提交之间的差异</span>
<span class="token function">git</span> commit_id1 commit_id2</code></pre>
<p><strong>周三:撤销操作练习</strong></p>
<pre style="white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important"><code class="prism language-bash"><span class="token comment"># 撤销对文件的修改(危险操作,谨慎使用)</span>
<span class="token function">git</span> checkout -- filename
<span class="token comment"># 从暂存区移除文件</span>
<span class="token function">git</span> reset HEAD filename
<span class="token comment"># 修改上次提交信息</span>
<span class="token function">git</span> commit --amend</code></pre>
<p><strong>周四:.gitignore深入理解</strong></p><ul><li>练习编写自定义.gitignore规则</li><li>理解通配符的使用:<code>*</code>、<code>?</code>、<code>[]</code></li><li>学习忽略已跟踪文件的方法</li></ul><p><strong>周五:实战练习</strong></p><ul><li>创建一个包含多种文件类型的项目</li><li>练习使用diff排查问题</li><li>编写详细的提交信息</li></ul><h4>十一、第3周学习计划:冲突解决</h4><h5>冲突处理训练</h5><p><strong>周一:理解冲突产生的原因</strong></p><ul><li>模拟多人协作场景</li><li>在两个地方修改同一文件的同一行</li><li>观察冲突产生的过程</li></ul><p><strong>周二:学习合并冲突解决</strong></p>
<pre style="white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important"><code class="prism language-bash"><span class="token comment"># 当pull时出现冲突</span>
<span class="token function">git</span> pull origin master
<span class="token comment"># 手动解决冲突后</span>
<span class="token function">git</span> <span class="token function">add</span> <span class="token builtin class-name">.</span>
<span class="token function">git</span> commit -m <span class="token string">"解决合并冲突"</span></code></pre>
<p><strong>周三:使用图形化工具</strong></p><ul><li>学习使用VSCode的冲突解决工具</li><li>尝试使用GitKraken或SourceTree</li><li>比较不同工具的优缺点</li></ul><p><strong>周四: rebase练习</strong></p>
<pre style="white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important"><code class="prism language-bash"><span class="token comment"># 使用rebase保持线性历史</span>
<span class="token function">git</span> pull --rebase origin master
<span class="token comment"># 解决rebase过程中的冲突</span>
<span class="token function">git</span> <span class="token function">add</span> <span class="token builtin class-name">.</span>
<span class="token function">git</span> rebase --continue</code></pre>
<p><strong>周五:预防冲突的最佳实践</strong></p><ul><li>勤推送,减少冲突机会</li><li>在开始工作前先pull更新</li><li>团队成员间及时沟通</li></ul><h4>十二、第4周学习计划:分支管理</h4><h5>分支操作全面掌握</h5><p><strong>周一:创建和切换分支</strong></p>
<pre style="white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important"><code class="prism language-bash"><span class="token comment"># 查看所有分支</span>
<span class="token function">git</span> branch -a
<span class="token comment"># 创建新分支</span>
<span class="token function">git</span> branch feature-new
<span class="token comment"># 切换分支</span>
<span class="token function">git</span> checkout feature-new
<span class="token comment"># 或者使用更现代的方式</span>
<span class="token function">git</span> switch feature-new</code></pre>
<p><strong>周二:分支合并练习</strong></p>
<pre style="white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important"><code class="prism language-bash"><span class="token comment"># 在feature分支完成开发后</span>
<span class="token function">git</span> switch master
<span class="token function">git</span> merge feature-new
<span class="token comment"># 使用no-ff保留分支历史</span>
<span class="token function">git</span> merge --no-ff feature-new</code></pre>
<p><strong>周三:远程分支操作</strong></p>
<pre style="white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important"><code class="prism language-bash"><span class="token comment"># 推送本地分支到远程</span>
<span class="token function">git</span> push -u origin feature-new
<span class="token comment"># 跟踪远程分支</span>
<span class="token function">git</span> checkout --track origin/feature-new
<span class="token comment"># 删除远程分支</span>
<span class="token function">git</span> push origin --delete feature-new</code></pre>
<p><strong>周四:分支策略学习</strong></p><ul><li>了解Git Flow工作流</li><li>学习主分支、开发分支、功能分支的作用</li><li>为个人项目设计合适的分支策略</li></ul><p><strong>周五:综合实战项目</strong></p><ul><li>模拟真实项目开发流程</li><li>从功能开发到测试再到合并</li><li>完整走一遍分支工作流</li></ul><h4>十三、进阶学习建议</h4><h5>完成基础学习后的方向</h5><p><strong>1. 参与开源项目</strong></p><ul><li>在Gitee上寻找感兴趣的开源项目</li><li>从提交issue开始</li><li>尝试修复简单的bug</li></ul><p><strong>2. 学习Git高级功能</strong></p><ul><li>存储临时修改:<code>git stash</code></li><li>二分法排查问题:<code>git bisect</code></li><li>子模块管理:<code>git submodule</code></li></ul><p><strong>3. 搭建个人博客或项目集</strong></p><ul><li>使用Gitee Pages部署静态网站</li><li>建立个人技术博客</li><li>展示学习成果和项目</li></ul><h5>持续学习资源</h5><ul><li>Gitee官方文档</li><li>Pro Git电子书(免费)</li><li>GitHub Learning Lab互动教程</li><li>技术社区的Git相关文章</li></ul><p>记住,熟练掌握Git需要时间和实践。建议在学习编程的同时,坚持使用Git管理所有代码,将其变成一种习惯。每次遇到问题都是学习的机会,通过解决问题来深化理解。</p></div><br><br>
来源:https://www.cnblogs.com/ljbguanli/p/19357387
頁: [1]
查看完整版本: 完整教程:Gitee完全新手教程