{"id":43053,"date":"2016-11-16T08:42:40","date_gmt":"2016-11-16T00:42:40","guid":{"rendered":"http:\/\/www.jiloc.com\/?p=43053"},"modified":"2016-11-16T10:18:51","modified_gmt":"2016-11-16T02:18:51","slug":"git-%e8%ae%be%e7%bd%ae%e8%bf%9c%e7%a8%8b%e4%bb%93%e5%ba%93-%e5%88%9d%e5%a7%8b%e5%8c%96push-%e5%9b%be%e6%96%87%e6%95%99%e7%a8%8b","status":"publish","type":"post","link":"http:\/\/jiloc.com\/43053.html","title":{"rendered":"Git \u8bbe\u7f6e\u8fdc\u7a0b\u4ed3\u5e93 \u521d\u59cb\u5316push \u56fe\u6587\u6559\u7a0b"},"content":{"rendered":"

Git \u2013 setting up a remote repository and doing an initial push<\/p>\n

There is a great deal of documentation and many posts on Git out there, so this is more of a note to self as I keep forgetting the steps needed to set up a remote repository and doing an initial \u201cpush\u201d.<\/p>\n

\u8fd9\u91cc\u8bb0\u5f55\u4e00\u4e0bpush\u8fdc\u7a0b\u4ed3\u5e93\u6240\u9700\u8981\u7684\u6b65\u9aa4\uff1a<\/p>\n

So, firstly setup the remote repository:<\/p>\n

\u9996\u5148\u8bbe\u7f6e\u8fdc\u7a0b\u4ed3\u5e93\uff1a<\/p>\n

ssh git@example.com\r\nmkdir my_project.git\r\ncd my_project.git\r\ngit init --bare\r\ngit update-server-info # If planning to serve via HTTP\r\nexit<\/pre>\n

On local machine:<\/p>\n

\u672c\u5730\u673a\u5668\uff1a<\/p>\n

cd my_project\r\ngit init\r\ngit add *\r\ngit commit -m \"My initial commit message\"\r\ngit remote add origin git@example.com:my_project.git\r\ngit push -u origin master<\/pre>\n

Done!<\/p>\n

\u5b8c\u6210\uff01<\/p>\n

Team members can now clone and track the remote repository using the following:<\/p>\n

\u5176\u4ed6\u56e2\u961f\u6210\u5458\u76f4\u63a5\u514b\u9686\u8fdc\u7a0b\u4ed3\u5e93\u5185\u5bb9\u5373\u53ef\uff1a<\/p>\n

git clone git@example.com:my_project.git\r\ncd my_project<\/pre>\n

Bonus<\/h4>\n

To have your terminal prompt display what branch you are currently on in green, add the following to your ~\/.bash_profile (I have my current directory displayed in cyan):<\/p>\n

function git-branch-name {\r\n  git symbolic-ref HEAD 2>\/dev\/null | cut -d\"\/\" -f 3\r\n}\r\nfunction git-branch-prompt {\r\n  local branch=`git-branch-name`\r\n  if [ $branch ]; then printf \" [%s]\" $branch; fi\r\n}\r\nPS1=\"\\u@\\h \\[\\033[0;36m\\]\\W\\[\\033[0m\\]\\[\\033[0;32m\\]\\$(git-branch-prompt)\\[\\033[0m\\] \\$ \"<\/pre>\n","protected":false},"excerpt":{"rendered":"

Git \u2013 setting up a remote repository and doing an initi […]<\/p>\n","protected":false},"author":1,"featured_media":43054,"comment_status":"open","ping_status":"closed","sticky":false,"template":"single-with-sidebar","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[36,31,129,109],"aioseo_notices":[],"_links":{"self":[{"href":"http:\/\/jiloc.com\/wp-json\/wp\/v2\/posts\/43053"}],"collection":[{"href":"http:\/\/jiloc.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/jiloc.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/jiloc.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/jiloc.com\/wp-json\/wp\/v2\/comments?post=43053"}],"version-history":[{"count":0,"href":"http:\/\/jiloc.com\/wp-json\/wp\/v2\/posts\/43053\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/jiloc.com\/wp-json\/wp\/v2\/media\/43054"}],"wp:attachment":[{"href":"http:\/\/jiloc.com\/wp-json\/wp\/v2\/media?parent=43053"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/jiloc.com\/wp-json\/wp\/v2\/categories?post=43053"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/jiloc.com\/wp-json\/wp\/v2\/tags?post=43053"}],"curies":[{"name":"wp","href":"http:\/\/api.w.org\/{rel}","templated":true}]}}