{"id":633,"date":"2025-08-28T16:57:34","date_gmt":"2025-08-28T08:57:34","guid":{"rendered":"https:\/\/www.subkme.com\/?p=633"},"modified":"2025-08-28T16:57:34","modified_gmt":"2025-08-28T08:57:34","slug":"github%e5%91%bd%e4%bb%a4%e8%a1%8c%e6%96%87%e4%bb%b6%e5%90%8c%e6%ad%a5%e5%ae%9e%e6%93%8d","status":"publish","type":"post","link":"https:\/\/subk.me\/?p=633","title":{"rendered":"github\u547d\u4ee4\u884c\u6587\u4ef6\u540c\u6b65\u5b9e\u64cd"},"content":{"rendered":"<h3>\u4e00\u3001\u786e\u4fdd Git \u4e0e GitHub \u8d26\u53f7\u5173\u8054<\/h3>\n<p>\u5982\u679c\u4f60\u5c1a\u672a\u914d\u7f6e Git \u4e0e GitHub \u8d26\u53f7\u7684\u5173\u8054\uff0c\u8bf7\u5148\u5b8c\u6210\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<ol>\n<li>\n<p><strong>\u8bbe\u7f6e Git \u7528\u6237\u4fe1\u606f<\/strong>\uff1a<\/p>\n<pre><code class=\"lang-bash language-bash bash\">git config --global user.name &quot;\u4f60\u7684\u540d\u5b57&quot;\ngit config --global user.email &quot;\u4f60\u7684 GitHub \u90ae\u7bb1&quot;<\/code><\/pre>\n<\/li>\n<li>\n<p><strong>SSH \u8ba4\u8bc1\uff08\u63a8\u8350\uff09<\/strong>\uff1a<\/p>\n<ul>\n<li>\u751f\u6210 SSH \u5bc6\u94a5\uff1a\n<pre><code class=\"lang-bash language-bash bash\">ssh-keygen -t ed25519 -C &quot;\u4f60\u7684\u90ae\u7bb1&quot;<\/code><\/pre>\n<p>\u6309\u56de\u8f66\u63a5\u53d7\u9ed8\u8ba4\u8def\u5f84\uff0c\u53ef\u8bbe\u7f6e\u5bc6\u7801\u6216\u7559\u7a7a\u3002<\/p><\/li>\n<li>\u67e5\u770b\u516c\u94a5\u5e76\u590d\u5236\uff1a\n<pre><code class=\"lang-bash language-bash bash\">cat ~\/.ssh\/id_ed25519.pub<\/code><\/pre><\/li>\n<li>\u767b\u5f55 GitHub\uff0c\u8fdb\u5165 <strong>Settings &gt; SSH and GPG keys &gt; New SSH key<\/strong>\uff0c\u7c98\u8d34\u516c\u94a5\u5e76\u4fdd\u5b58\u3002<\/li>\n<li>\u6d4b\u8bd5\u8fde\u63a5\uff1a\n<pre><code class=\"lang-bash language-bash bash\">ssh -T git@github.com<\/code><\/pre><\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>HTTPS \u8ba4\u8bc1\uff08\u5907\u9009\uff09<\/strong>\uff1a<\/p>\n<ul>\n<li>\u751f\u6210\u4e2a\u4eba\u8bbf\u95ee\u4ee4\u724c\uff08PAT\uff09\uff1a\u767b\u5f55 GitHub\uff0c<strong>Settings &gt; Developer settings &gt; Personal access tokens &gt; Generate new token<\/strong>\uff0c\u9009\u62e9 <code>repo<\/code> \u6743\u9650\u3002<\/li>\n<li>\u63a8\u9001\u6216\u62c9\u53d6\u65f6\u4f7f\u7528 PAT \u66ff\u4ee3\u5bc6\u7801\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u68c0\u67e5\u8fdc\u7a0b\u4ed3\u5e93<\/strong>\uff1a<\/p>\n<ul>\n<li>\u786e\u4fdd\u672c\u5730\u4ed3\u5e93\u5df2\u5173\u8054 GitHub \u4ed3\u5e93\uff1a\n<pre><code class=\"lang-bash language-bash bash\">git remote -v<\/code><\/pre><\/li>\n<li>\u5982\u679c\u672a\u5173\u8054\uff0c\u6dfb\u52a0\u8fdc\u7a0b\u4ed3\u5e93\uff1a\n<pre><code class=\"lang-bash language-bash bash\">git remote add origin git@github.com:\u7528\u6237\u540d\/\u4ed3\u5e93\u540d.git<\/code><\/pre>\n<p>\u6216\uff08HTTPS\uff09\uff1a<\/p>\n<pre><code class=\"lang-bash language-bash bash\">git remote add origin https:\/\/github.com\/\u7528\u6237\u540d\/\u4ed3\u5e93\u540d.git<\/code><\/pre><\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<hr \/>\n<h3>\u4e8c\u3001\u4e0e GitHub \u4ed3\u5e93\u4ea4\u4e92\u7684 Git \u547d\u4ee4<\/h3>\n<p>\u4ee5\u4e0b\u662f\u4f60\u5728\u7ec8\u7aef\u4e2d\u4e0e GitHub \u4ed3\u5e93\u4ea4\u4e92\u7684\u5b8c\u6574\u6d41\u7a0b\uff0c\u6db5\u76d6\u62c9\u53d6\u3001\u4fee\u6539\u3001\u63d0\u4ea4\u548c\u63a8\u9001\uff1a<\/p>\n<h4>1. <strong>\u62c9\u53d6 GitHub \u4ed3\u5e93\u5185\u5bb9<\/strong><\/h4>\n<ul>\n<li>\n<p><strong>\u514b\u9686\u4ed3\u5e93\uff08\u9996\u6b21\u83b7\u53d6\uff09<\/strong>\uff1a\n\u5982\u679c\u4f60\u8fd8\u6ca1\u6709\u672c\u5730\u4ed3\u5e93\uff0c\u514b\u9686 GitHub \u4ed3\u5e93\uff1a<\/p>\n<pre><code class=\"lang-bash language-bash bash\">git clone git@github.com:\u7528\u6237\u540d\/\u4ed3\u5e93\u540d.git<\/code><\/pre>\n<p>\u6216\uff08HTTPS\uff09\uff1a<\/p>\n<pre><code class=\"lang-bash language-bash bash\">git clone https:\/\/github.com\/\u7528\u6237\u540d\/\u4ed3\u5e93\u540d.git<\/code><\/pre>\n<p>\u514b\u9686\u540e\uff0c\u8fdb\u5165\u4ed3\u5e93\u76ee\u5f55\uff1a<\/p>\n<pre><code class=\"lang-bash language-bash bash\">cd \u4ed3\u5e93\u540d<\/code><\/pre>\n<\/li>\n<li>\n<p><strong>\u62c9\u53d6\u66f4\u65b0\uff08\u5df2\u6709\u672c\u5730\u4ed3\u5e93\uff09<\/strong>\uff1a\n\u5982\u679c\u672c\u5730\u5df2\u6709\u4ed3\u5e93\uff0c\u8fdb\u5165\u76ee\u5f55\uff1a<\/p>\n<pre><code class=\"lang-bash language-bash bash\">cd \u4ed3\u5e93\u8def\u5f84<\/code><\/pre>\n<p>\u62c9\u53d6\u8fdc\u7a0b\u4ed3\u5e93\u7684\u6700\u65b0\u5185\u5bb9\uff1a<\/p>\n<pre><code class=\"lang-bash language-bash bash\">git pull origin main<\/code><\/pre>\n<ul>\n<li>\u66ff\u6362 <code>main<\/code> \u4e3a\u4f60\u7684\u9ed8\u8ba4\u5206\u652f\uff08\u5982 <code>master<\/code>\uff09\u3002<\/li>\n<li>\u5982\u679c\u6709\u51b2\u7a81\uff0cGit \u4f1a\u63d0\u793a\uff0c\u9700\u624b\u52a8\u89e3\u51b3\uff08\u89c1\u4e0b\u65b9\u201c\u5904\u7406\u51b2\u7a81\u201d\uff09\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h4>2. <strong>\u4fee\u6539\u672c\u5730\u6587\u4ef6\u5e76\u540c\u6b65\u5230 GitHub<\/strong><\/h4>\n<p>\u5047\u8bbe\u4f60\u5728\u672c\u5730\u7528 VS Code \u6216\u5176\u4ed6\u7f16\u8f91\u5668\u4fee\u6539\u4e86\u6587\u4ef6\uff0c\u4ee5\u4e0b\u662f\u540c\u6b65\u6b65\u9aa4\uff1a<\/p>\n<ol>\n<li>\n<p><strong>\u68c0\u67e5\u4fee\u6539\u72b6\u6001<\/strong>\uff1a<\/p>\n<pre><code class=\"lang-bash language-bash bash\">git status<\/code><\/pre>\n<p>\u663e\u793a\u5df2\u4fee\u6539\uff08Modified\uff09\u3001\u65b0\u589e\uff08Untracked\uff09\u6216\u5220\u9664\uff08Deleted\uff09\u7684\u6587\u4ef6\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u6dfb\u52a0\u4fee\u6539\u5230\u6682\u5b58\u533a<\/strong>\uff1a<\/p>\n<ul>\n<li>\u6dfb\u52a0\u7279\u5b9a\u6587\u4ef6\uff1a\n<pre><code class=\"lang-bash language-bash bash\">git add \u6587\u4ef6\u540d<\/code><\/pre>\n<p>\u4f8b\u5982\uff1a<code>git add index.html<\/code><\/p><\/li>\n<li>\u6dfb\u52a0\u6240\u6709\u4fee\u6539\uff1a\n<pre><code class=\"lang-bash language-bash bash\">git add .<\/code><\/pre><\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u63d0\u4ea4\u4fee\u6539\u5230\u672c\u5730\u4ed3\u5e93<\/strong>\uff1a<\/p>\n<pre><code class=\"lang-bash language-bash bash\">git commit -m &quot;\u63cf\u8ff0\u4f60\u7684\u4fee\u6539\u5185\u5bb9&quot;<\/code><\/pre>\n<p>\u4f8b\u5982\uff1a<code>git commit -m &quot;\u66f4\u65b0\u4e86\u4e3b\u9875\u6837\u5f0f&quot;<\/code><\/p>\n<\/li>\n<li>\n<p><strong>\u63a8\u9001\u4fee\u6539\u5230 GitHub<\/strong>\uff1a<\/p>\n<pre><code class=\"lang-bash language-bash bash\">git push origin main<\/code><\/pre>\n<ul>\n<li>\u786e\u4fdd\u5206\u652f\u540d\uff08<code>main<\/code>\uff09\u4e0e\u8fdc\u7a0b\u4ed3\u5e93\u4e00\u81f4\u3002<\/li>\n<li>\u5982\u679c\u662f\u9996\u6b21\u63a8\u9001\u65b0\u5206\u652f\uff0c\u9700\u8bbe\u7f6e\u4e0a\u6e38\u5206\u652f\uff1a\n<pre><code class=\"lang-bash language-bash bash\">git push --set-upstream origin main<\/code><\/pre><\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h4>3. <strong>\u5904\u7406\u51b2\u7a81<\/strong><\/h4>\n<ul>\n<li>\u5982\u679c <code>git pull<\/code> \u6216 <code>git push<\/code> \u9047\u5230\u51b2\u7a81\uff08\u4f8b\u5982\u672c\u5730\u548c\u8fdc\u7a0b\u4fee\u6539\u4e86\u540c\u4e00\u6587\u4ef6\uff09\uff1a\n<ol>\n<li>\u8fd0\u884c <code>git pull<\/code> \u65f6\uff0cGit \u4f1a\u6807\u8bb0\u51b2\u7a81\u6587\u4ef6\uff0c\u6253\u5f00\u6587\u4ef6\uff0c\u627e\u5230 <code>&lt;&lt;&lt;&lt;&lt;&lt;&lt; HEAD<\/code> \u548c <code>&gt;&gt;&gt;&gt;&gt;&gt;&gt;<\/code> \u6807\u8bb0\u3002<\/li>\n<li>\u624b\u52a8\u7f16\u8f91\u4fdd\u7559\u6240\u9700\u5185\u5bb9\uff0c\u5220\u9664\u51b2\u7a81\u6807\u8bb0\u3002<\/li>\n<li>\u6dfb\u52a0\u5e76\u63d0\u4ea4\uff1a\n<pre><code class=\"lang-bash language-bash bash\">git add .\ngit commit -m &quot;\u89e3\u51b3\u51b2\u7a81&quot;\ngit push origin main<\/code><\/pre><\/li>\n<\/ol><\/li>\n<\/ul>\n<h4>4. <strong>\u9a8c\u8bc1\u540c\u6b65<\/strong><\/h4>\n<ul>\n<li>\u63a8\u9001\u540e\uff0c\u8bbf\u95ee GitHub \u4ed3\u5e93\u9875\u9762\uff0c\u786e\u8ba4\u6587\u4ef6\u662f\u5426\u66f4\u65b0\u3002<\/li>\n<\/ul>\n<hr \/>\n<h3>\u4e09\u3001\u5178\u578b\u5de5\u4f5c\u6d41\u793a\u4f8b<\/h3>\n<p>\u5047\u8bbe\u4f60\u5728\u672c\u5730\u4fee\u6539\u4e86\u6587\u4ef6\uff0c\u5b8c\u6574\u6d41\u7a0b\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"lang-bash language-bash bash\">cd \u4ed3\u5e93\u8def\u5f84\ngit pull origin main          # \u62c9\u53d6\u6700\u65b0\u5185\u5bb9\n# \u4fee\u6539\u6587\u4ef6\uff08\u7528 VS Code \u6216\u5176\u4ed6\u7f16\u8f91\u5668\uff09\ngit status                    # \u67e5\u770b\u4fee\u6539\ngit add .                     # \u6dfb\u52a0\u6240\u6709\u4fee\u6539\ngit commit -m &quot;\u66f4\u65b0\u5185\u5bb9&quot;      # \u63d0\u4ea4\ngit push origin main          # \u63a8\u9001\u5230 GitHub<\/code><\/pre>\n<hr \/>\n<h3>\u56db\u3001\u5e38\u89c1\u95ee\u9898\u4e0e\u89e3\u51b3\u65b9\u6848<\/h3>\n<ol>\n<li>\n<p><strong>\u63a8\u9001\u5931\u8d25\uff08401\/403 \u9519\u8bef\uff09<\/strong>\uff1a<\/p>\n<ul>\n<li>SSH\uff1a\u786e\u4fdd\u516c\u94a5\u5df2\u6dfb\u52a0\u5230 GitHub\uff0c\u8fd0\u884c <code>ssh -T git@github.com<\/code> \u6d4b\u8bd5\u3002<\/li>\n<li>HTTPS\uff1a\u4f7f\u7528 PAT \u767b\u5f55\uff0c\u68c0\u67e5\u662f\u5426\u8fc7\u671f\u3002<\/li>\n<li>\u786e\u8ba4\u8fdc\u7a0b URL \u6b63\u786e\uff1a<code>git remote -v<\/code>\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u4ed3\u5e93\u672a\u5173\u8054<\/strong>\uff1a<\/p>\n<ul>\n<li>\u68c0\u67e5\uff1a<code>git remote -v<\/code>\u3002<\/li>\n<li>\u6dfb\u52a0\uff1a<code>git remote add origin git@github.com:\u7528\u6237\u540d\/\u4ed3\u5e93\u540d.git<\/code>\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u5206\u652f\u4e0d\u5339\u914d<\/strong>\uff1a<\/p>\n<ul>\n<li>\u786e\u8ba4\u8fdc\u7a0b\u5206\u652f\u540d\uff1a<code>git branch -r<\/code>\u3002<\/li>\n<li>\u5207\u6362\u5230\u6b63\u786e\u5206\u652f\uff1a<code>git checkout main<\/code>\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u6587\u4ef6\u672a\u8ddf\u8e2a<\/strong>\uff1a<\/p>\n<ul>\n<li>\u65b0\u6587\u4ef6\u9700\u7528 <code>git add \u6587\u4ef6\u540d<\/code> \u6dfb\u52a0\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<hr \/>\n<h3>\u4e94\u3001\u5173\u952e\u77e5\u8bc6\u70b9\u4f9b\u6df1\u5165\u5b66\u4e60<\/h3>\n<ol>\n<li>\n<p><strong>Git \u6838\u5fc3\u6982\u5ff5<\/strong>\uff1a<\/p>\n<ul>\n<li><strong>\u5de5\u4f5c\u533a<\/strong>\uff1a\u672c\u5730\u6587\u4ef6\u3002<\/li>\n<li><strong>\u6682\u5b58\u533a<\/strong>\uff1a<code>git add<\/code> \u540e\u7684\u4fee\u6539\u3002<\/li>\n<li><strong>\u7248\u672c\u5e93<\/strong>\uff1a<code>git commit<\/code> \u540e\u7684\u63d0\u4ea4\u5386\u53f2\u3002<\/li>\n<li><strong>\u8fdc\u7a0b\u4ed3\u5e93<\/strong>\uff1aGitHub \u4e0a\u7684\u4ed3\u5e93\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u5e38\u7528\u547d\u4ee4<\/strong>\uff1a<\/p>\n<ul>\n<li><code>git clone<\/code>\uff1a\u514b\u9686\u4ed3\u5e93\u3002<\/li>\n<li><code>git pull<\/code>\uff1a\u62c9\u53d6\u5e76\u5408\u5e76\u66f4\u65b0\u3002<\/li>\n<li><code>git add<\/code>\uff1a\u6dfb\u52a0\u4fee\u6539\u5230\u6682\u5b58\u533a\u3002<\/li>\n<li><code>git commit<\/code>\uff1a\u63d0\u4ea4\u5230\u672c\u5730\u4ed3\u5e93\u3002<\/li>\n<li><code>git push<\/code>\uff1a\u63a8\u9001\u81f3\u8fdc\u7a0b\u4ed3\u5e93\u3002<\/li>\n<li><code>git status<\/code>\uff1a\u67e5\u770b\u72b6\u6001\u3002<\/li>\n<li><code>git log<\/code>\uff1a\u67e5\u770b\u63d0\u4ea4\u5386\u53f2\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u5206\u652f\u7ba1\u7406<\/strong>\uff1a<\/p>\n<ul>\n<li>\u521b\u5efa\u5206\u652f\uff1a<code>git branch \u65b0\u5206\u652f\u540d<\/code>\u3002<\/li>\n<li>\u5207\u6362\u5206\u652f\uff1a<code>git checkout \u65b0\u5206\u652f\u540d<\/code>\u3002<\/li>\n<li>\u63a8\u9001\u5206\u652f\uff1a<code>git push origin \u65b0\u5206\u652f\u540d<\/code>\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u5b66\u4e60\u8d44\u6e90<\/strong>\uff1a<\/p>\n<ul>\n<li><strong>Git \u5b98\u7f51<\/strong>\uff1agit-scm.com \u7684 Pro Git \u4e66\u7c4d\u3002<\/li>\n<li><strong>GitHub \u6587\u6863<\/strong>\uff1adocs.github.com\uff0c\u5b66\u4e60 SSH \u914d\u7f6e\u548c\u4ed3\u5e93\u7ba1\u7406\u3002<\/li>\n<li><strong>\u4e2d\u6587\u6559\u7a0b<\/strong>\uff1a\u83dc\u9e1f\u6559\u7a0b\uff08runoob.com\uff09\u6216\u5ed6\u96ea\u5cf0\u7684 Git \u6559\u7a0b\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<hr \/>\n<h3>\u516d\u3001\u5feb\u901f\u4e0a\u624b\u5efa\u8bae<\/h3>\n<ol>\n<li><strong>\u5b9e\u8df5<\/strong>\uff1a\u514b\u9686\u4e00\u4e2a\u6d4b\u8bd5\u4ed3\u5e93\uff0c\u4fee\u6539\u6587\u4ef6\uff0c\u8fd0\u884c <code>git add<\/code>\u3001<code>commit<\/code>\u3001<code>push<\/code>\u3002<\/li>\n<li><strong>\u5b9a\u671f\u62c9\u53d6<\/strong>\uff1a\u4fee\u6539\u524d\u8fd0\u884c <code>git pull<\/code>\uff0c\u907f\u514d\u51b2\u7a81\u3002<\/li>\n<li><strong>\u5907\u4efd<\/strong>\uff1a\u91cd\u8981\u4fee\u6539\u524d\u786e\u4fdd\u63d0\u4ea4\u6216\u5907\u4efd\u3002<\/li>\n<li><strong>\u7528 SSH<\/strong>\uff1a\u914d\u7f6e SSH \u907f\u514d\u9891\u7e41\u8f93\u5165\u51ed\u636e\u3002<\/li>\n<\/ol>","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u786e\u4fdd Git \u4e0e GitHub \u8d26\u53f7\u5173\u8054 \u5982\u679c\u4f60\u5c1a\u672a\u914d\u7f6e Git \u4e0e GitHub \u8d26\u53f7\u7684\u5173\u8054\uff0c\u8bf7\u5148\u5b8c\u6210\u4ee5 [&hellip;]<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[36],"class_list":["post-633","post","type-post","status-publish","format-standard","hentry","category-it","tag-github"],"_links":{"self":[{"href":"https:\/\/subk.me\/index.php?rest_route=\/wp\/v2\/posts\/633","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/subk.me\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/subk.me\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/subk.me\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/subk.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=633"}],"version-history":[{"count":1,"href":"https:\/\/subk.me\/index.php?rest_route=\/wp\/v2\/posts\/633\/revisions"}],"predecessor-version":[{"id":634,"href":"https:\/\/subk.me\/index.php?rest_route=\/wp\/v2\/posts\/633\/revisions\/634"}],"wp:attachment":[{"href":"https:\/\/subk.me\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=633"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/subk.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=633"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/subk.me\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=633"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}