{"id":1583,"date":"2015-04-18T20:54:09","date_gmt":"2015-04-18T12:54:09","guid":{"rendered":"http:\/\/www.51cos.com\/?p=1583"},"modified":"2015-04-18T20:58:00","modified_gmt":"2015-04-18T12:58:00","slug":"%e5%88%9b%e5%bb%bagit%e7%a7%81%e6%9c%89%e4%bb%93%e5%ba%93","status":"publish","type":"post","link":"http:\/\/www.51cos.com\/?p=1583","title":{"rendered":"\u521b\u5efagit\u79c1\u6709\u4ed3\u5e93"},"content":{"rendered":"<p>\u4ee5ubuntu\u670d\u52a1\u5668\u4e3a\u4f8b\uff0c\u5982\u679c\u8981\u521b\u5efa\u5c0f\u8303\u56f4\u7684\u79c1\u6709git\u670d\u52a1\u5668\uff0c\u662f\u975e\u5e38\u7b80\u5355\u7684\uff0c\u53ea\u9700\u8981\u5982\u4e0b\u51e0\u4e2a\u7b80\u5355\u6b65\u9aa4\uff1a<\/p>\n<p>Step 1: \u5b89\u88c5git<\/p>\n<p>\u76f4\u63a5\u901a\u8fc7sudo apt-get install git\u5373\u53ef\u5b8c\u6210\u3002<\/p>\n<p>Step 2: \u521b\u5efagit\u7528\u6237<\/p>\n<p>git\u7528\u6237\u7528\u6765\u901a\u8fc7SSH\u8fde\u63a5git\u670d\u52a1\uff0c\u8f93\u5165\u547d\u4ee4\uff1a<\/p>\n<p><span class=\"katex math inline\">sudo adduser git<\/p>\n<p>Step 3: \u521b\u5efa\u8bc1\u4e66\u767b\u5f55<\/p>\n<p>\u9996\u5148\u6536\u96c6\u6240\u6709\u9700\u8981\u767b\u5f55\u7684\u7528\u6237\u516c\u94a5\uff0c\u7136\u540e\u5bfc\u5165\u5230\/home\/git\/.ssh\/authorized_keys\u6587\u4ef6\u5373\u53ef\u3002<\/p>\n<p>Step 4: \u521d\u59cb\u5316git\u4ed3\u5e93<\/p>\n<p>\u5047\u8bbe\u4ed3\u5e93\u4f4d\u4e8e\/srv\/sample.git\uff0c\u5728\/srv\u76ee\u5f55\u4e0b\u8f93\u5165\u547d\u4ee4\uff1a<\/span> sudo git init &#8211;bare sample.git<\/p>\n<p>\u8fd9\u6837\u5c31\u521b\u5efa\u4e86\u4e00\u4e2a\u88f8\u4ed3\u5e93\uff0c\u88f8\u4ed3\u5e93\u6ca1\u6709working dir\uff0c\u56e0\u4e3a\u670d\u52a1\u5668\u4e0a\u7684git\u4ed3\u5e93\u7eaf\u7cb9\u662f\u4e3a\u4e86\u5171\u4eab\uff0c\u4ed3\u5e93\u76ee\u5f55\u4e00\u822c\u4ee5.git\u7ed3\u5c3e\u3002\u7136\u540e\u628aowner\u6539\u4e3agit\uff1a<\/p>\n<p><span class=\"katex math inline\">sudo chown -R git:git sample.git<\/p>\n<p>Step 5: \u9632\u6b62\u767b\u5f55shell<\/p>\n<p>\u51fa\u4e8e\u5b89\u5168\u8003\u8651\uff0cgit\u7528\u6237\u4e0d\u5e94\u8be5\u767b\u5f55shell\uff0c\u53ef\u4ee5\u7f16\u8f91\/etc\/passwd\uff0c\u627e\u5230\u7c7b\u4f3c\u4e00\u884c\uff1a<\/p>\n<p>git:x:1001:1001:,,,:\/home\/git:\/bin\/bash<\/p>\n<p>\u6539\u4e3a\uff1a<\/p>\n<p>git:x:1001:1001:,,,:\/home\/git:\/usr\/bin\/git-shell<\/p>\n<p>\u8fd9\u6837\uff0cgit\u7528\u6237\u53ef\u4ee5\u6b63\u5e38\u901a\u8fc7ssh\u4f7f\u7528git\uff0c\u4f46\u65e0\u6cd5\u767b\u5f55shell\u3002<\/p>\n<p>Step 6: \u514b\u9686\u4ed3\u5e93<\/p>\n<p>\u5728\u5ba2\u6237\u7aef\u5c31\u53ef\u4ee5\u901a\u8fc7ssh\u514b\u9686\u4ed3\u5e93\u4e86\uff1a<\/span> git clone git@server:\/srv\/sample.git<br \/>\nCloning into &#8216;sample&#8217;&#8230;<br \/>\nwarning: You appear to have cloned an empty repository.<\/p>\n<p>\u7136\u540e\uff0c\u5c31\u53ef\u4ee5\u6b63\u5e38\u63a8\u9001\u4e86\uff1a<\/p>\n<p><span class=\"katex math inline\">touch README<\/span> git add README<br \/>\n<span class=\"katex math inline\">git commit -m &#8220;add readme&#8221;<\/span> git push origin master<br \/>\nCounting objects: 3, done.<br \/>\nWriting objects: 100% (3\/3), 212 bytes, done.<br \/>\nTotal 3 (delta 0), reused 0 (delta 0)<br \/>\nTo git@ubuntu:\/srv\/sample.git<br \/>\n * [new branch]      master -> master<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4ee5ubuntu\u670d\u52a1\u5668\u4e3a\u4f8b\uff0c\u5982\u679c\u8981\u521b\u5efa\u5c0f\u8303\u56f4\u7684\u79c1\u6709git\u670d\u52a1\u5668\uff0c\u662f\u975e\u5e38\u7b80\u5355\u7684\uff0c\u53ea\u9700\u8981\u5982\u4e0b\u51e0\u4e2a\u7b80\u5355\u6b65\u9aa4\uff1a Step [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-1583","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"http:\/\/www.51cos.com\/index.php?rest_route=\/wp\/v2\/posts\/1583","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.51cos.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.51cos.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.51cos.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.51cos.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1583"}],"version-history":[{"count":0,"href":"http:\/\/www.51cos.com\/index.php?rest_route=\/wp\/v2\/posts\/1583\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.51cos.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1583"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.51cos.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1583"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.51cos.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1583"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}