{"id":8482,"date":"2022-09-02T11:28:04","date_gmt":"2022-09-02T11:28:04","guid":{"rendered":"https:\/\/clustercs.com\/kb\/?docs=docly-documentation\/domain-management\/utility\/how-to-set-up-a-git-bare-repository-for-code-pushes"},"modified":"2022-09-19T12:38:44","modified_gmt":"2022-09-19T12:38:44","slug":"how-to-set-up-a-git-bare-repository-for-code-pushes-in-clustercs","status":"publish","type":"docs","link":"https:\/\/clustercs.com\/kb\/docs\/clustercs\/domain-management\/utility\/how-to-set-up-a-git-bare-repository-for-code-pushes-in-clustercs\/","title":{"rendered":"How to set up a GIT bare repository for code pushes"},"content":{"rendered":"\n<p><\/p>\n\n\n\n<p>Developers often need an easy and simple way of sharing code changes to a development and production setup.<\/p>\n\n\n\n<p>This can be easily achieved by setting up a git bare repository and setting it as a remote git repository in your codebase. Git bare repositories are great because it\u2019s the perfect setup for sharing code.<\/p>\n\n\n\n<p>In order to make this work, we first need to go to domains and click manage on the domain we want to do the setup.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/clustercs.com\/oldkb\/wp-content\/uploads\/2018\/11\/clustercs_domain_listing-1024x663.png\"><img decoding=\"async\" src=\"https:\/\/clustercs.com\/oldkb\/wp-content\/uploads\/2018\/11\/clustercs_domain_listing-1024x663.png\" alt=\"\"\/><\/a><\/figure>\n\n\n\n<p>The next step is to enable SSH as a login method since we\u2019re going to use that as the authentication method for getting to the bare git repo.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/clustercs.com\/oldkb\/wp-content\/uploads\/2018\/11\/clustercs_ssh_login-1024x490.png\"><img decoding=\"async\" src=\"https:\/\/clustercs.com\/oldkb\/wp-content\/uploads\/2018\/11\/clustercs_ssh_login-1024x490.png\" alt=\"\"\/><\/a><\/figure>\n\n\n\n<p>Now we can use the domain credentials to login via SSH on the server as the domain\u2019s user. In case you need to set up your server firewall to accept SSH connections you can read the&nbsp;<a href=\"https:\/\/clustercs.com\/kb\/docs\/clustercs\/server-setup\/firewall\/setting-firewall-rules\/\" target=\"_blank\" rel=\"noopener\">Firewall Setup KB article<\/a>.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>Once logged in, your domain\u2019s root folder is set up at \/home\/~domain_username . Make sure you\u2019re in the domain root folder before carrying on with the tutorial. We are assuming you are deploying for the production environment. If you are using Dev Environments and want to deploy to a different environment, please replace \u201clive\u201d with your environment name in the commands bellow.<\/p><\/blockquote>\n\n\n\n<pre class=\"wp-block-code has-medium-font-size\"><code>cd web\/live\nmkdir .gitrepo\ncd .gitrepo\/\ngit init --bare\ncd hooks\/\ntouch post-receive\nchmod +x post-receive\nvim post-receive<\/code><\/pre>\n\n\n\n<p>Now in the post-receive file, we\u2019re going to set up specific code that will checkout the received changes automatically in the domain\u2019s root folder. This can also be set up for other usefull functions like making sure file permissions are correctly setup, or specific post-deployment scripts are run.<\/p>\n\n\n\n<p>We have two options for setting up the checkout:<\/p>\n\n\n\n<p>1. Checking out only a specific branch<\/p>\n\n\n\n<pre class=\"wp-block-code has-medium-font-size\"><code>#!\/bin\/sh\nGIT_WORK_TREE=..\/ git checkout -f &#91;branch]<\/code><\/pre>\n\n\n\n<p>2. Checking out any receiving branch (this is useful for a development setup)<\/p>\n\n\n\n<pre class=\"wp-block-code has-medium-font-size\"><code>#!\/bin\/sh\nwhile read oldrev newrev refdo\n    branch=\u00b4echo $ref | cut -d\/ -f3\u00b4\nGIT_WORK_TREE=..\/ git checkout -f $branch\ndone.<\/code><\/pre>\n\n\n\n<p>Once that\u2019s done, you can use the remote repository after you add it to your local git repository using the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code has-medium-font-size\"><code>git remote add &#91;remote-name] ssh:\/\/&#91;user]@&#91;site]\/~\/web\/live\/.gitrepo<\/code><\/pre>\n\n\n\n<p>Now you can just push your code changes to the remote git bare repository and see your changes appear on the server.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Developers often need an easy and simple way of sharing code changes to a development and production setup. This can be easily achieved by setting up a git bare repository and setting it as a remote git repository in your codebase. Git bare repositories are great because it\u2019s the perfect setup for sharing code. In [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":8476,"menu_order":7,"comment_status":"open","ping_status":"closed","template":"","doc_tag":[],"class_list":["post-8482","docs","type-docs","status-publish","hentry","no-post-thumbnail"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.9 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to set up a GIT bare repository for code pushes - ClusterCS Knowledge Base<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/clustercs.com\/kb\/docs\/clustercs\/domain-management\/utility\/how-to-set-up-a-git-bare-repository-for-code-pushes-in-clustercs\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to set up a GIT bare repository for code pushes - ClusterCS Knowledge Base\" \/>\n<meta property=\"og:description\" content=\"Developers often need an easy and simple way of sharing code changes to a development and production setup. This can be easily achieved by setting up a git bare repository and setting it as a remote git repository in your codebase. Git bare repositories are great because it\u2019s the perfect setup for sharing code. In [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/clustercs.com\/kb\/docs\/clustercs\/domain-management\/utility\/how-to-set-up-a-git-bare-repository-for-code-pushes-in-clustercs\/\" \/>\n<meta property=\"og:site_name\" content=\"ClusterCS Knowledge Base\" \/>\n<meta property=\"article:modified_time\" content=\"2022-09-19T12:38:44+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/clustercs.com\/oldkb\/wp-content\/uploads\/2018\/11\/clustercs_domain_listing-1024x663.png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/clustercs.com\/kb\/docs\/clustercs\/domain-management\/utility\/how-to-set-up-a-git-bare-repository-for-code-pushes-in-clustercs\/\",\"url\":\"https:\/\/clustercs.com\/kb\/docs\/clustercs\/domain-management\/utility\/how-to-set-up-a-git-bare-repository-for-code-pushes-in-clustercs\/\",\"name\":\"How to set up a GIT bare repository for code pushes - ClusterCS Knowledge Base\",\"isPartOf\":{\"@id\":\"https:\/\/clustercs.com\/kb\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/clustercs.com\/kb\/docs\/clustercs\/domain-management\/utility\/how-to-set-up-a-git-bare-repository-for-code-pushes-in-clustercs\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/clustercs.com\/kb\/docs\/clustercs\/domain-management\/utility\/how-to-set-up-a-git-bare-repository-for-code-pushes-in-clustercs\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/clustercs.com\/oldkb\/wp-content\/uploads\/2018\/11\/clustercs_domain_listing-1024x663.png\",\"datePublished\":\"2022-09-02T11:28:04+00:00\",\"dateModified\":\"2022-09-19T12:38:44+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/clustercs.com\/kb\/docs\/clustercs\/domain-management\/utility\/how-to-set-up-a-git-bare-repository-for-code-pushes-in-clustercs\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/clustercs.com\/kb\/docs\/clustercs\/domain-management\/utility\/how-to-set-up-a-git-bare-repository-for-code-pushes-in-clustercs\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/clustercs.com\/kb\/docs\/clustercs\/domain-management\/utility\/how-to-set-up-a-git-bare-repository-for-code-pushes-in-clustercs\/#primaryimage\",\"url\":\"https:\/\/clustercs.com\/oldkb\/wp-content\/uploads\/2018\/11\/clustercs_domain_listing-1024x663.png\",\"contentUrl\":\"https:\/\/clustercs.com\/oldkb\/wp-content\/uploads\/2018\/11\/clustercs_domain_listing-1024x663.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/clustercs.com\/kb\/docs\/clustercs\/domain-management\/utility\/how-to-set-up-a-git-bare-repository-for-code-pushes-in-clustercs\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/clustercs.com\/kb\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"ClusterCS Documentation\",\"item\":\"https:\/\/clustercs.com\/kb\/docs\/clustercs\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Domain Management\",\"item\":\"https:\/\/clustercs.com\/kb\/docs\/clustercs\/domain-management\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Utility\",\"item\":\"https:\/\/clustercs.com\/kb\/docs\/clustercs\/domain-management\/utility\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"How to set up a GIT bare repository for code pushes\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/clustercs.com\/kb\/#website\",\"url\":\"https:\/\/clustercs.com\/kb\/\",\"name\":\"ClusterCS Knowledge Base\",\"description\":\"Welcome to ClusterCS Documentation\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/clustercs.com\/kb\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to set up a GIT bare repository for code pushes - ClusterCS Knowledge Base","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/clustercs.com\/kb\/docs\/clustercs\/domain-management\/utility\/how-to-set-up-a-git-bare-repository-for-code-pushes-in-clustercs\/","og_locale":"en_US","og_type":"article","og_title":"How to set up a GIT bare repository for code pushes - ClusterCS Knowledge Base","og_description":"Developers often need an easy and simple way of sharing code changes to a development and production setup. This can be easily achieved by setting up a git bare repository and setting it as a remote git repository in your codebase. Git bare repositories are great because it\u2019s the perfect setup for sharing code. In [&hellip;]","og_url":"https:\/\/clustercs.com\/kb\/docs\/clustercs\/domain-management\/utility\/how-to-set-up-a-git-bare-repository-for-code-pushes-in-clustercs\/","og_site_name":"ClusterCS Knowledge Base","article_modified_time":"2022-09-19T12:38:44+00:00","og_image":[{"url":"https:\/\/clustercs.com\/oldkb\/wp-content\/uploads\/2018\/11\/clustercs_domain_listing-1024x663.png","type":"","width":"","height":""}],"twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/clustercs.com\/kb\/docs\/clustercs\/domain-management\/utility\/how-to-set-up-a-git-bare-repository-for-code-pushes-in-clustercs\/","url":"https:\/\/clustercs.com\/kb\/docs\/clustercs\/domain-management\/utility\/how-to-set-up-a-git-bare-repository-for-code-pushes-in-clustercs\/","name":"How to set up a GIT bare repository for code pushes - ClusterCS Knowledge Base","isPartOf":{"@id":"https:\/\/clustercs.com\/kb\/#website"},"primaryImageOfPage":{"@id":"https:\/\/clustercs.com\/kb\/docs\/clustercs\/domain-management\/utility\/how-to-set-up-a-git-bare-repository-for-code-pushes-in-clustercs\/#primaryimage"},"image":{"@id":"https:\/\/clustercs.com\/kb\/docs\/clustercs\/domain-management\/utility\/how-to-set-up-a-git-bare-repository-for-code-pushes-in-clustercs\/#primaryimage"},"thumbnailUrl":"https:\/\/clustercs.com\/oldkb\/wp-content\/uploads\/2018\/11\/clustercs_domain_listing-1024x663.png","datePublished":"2022-09-02T11:28:04+00:00","dateModified":"2022-09-19T12:38:44+00:00","breadcrumb":{"@id":"https:\/\/clustercs.com\/kb\/docs\/clustercs\/domain-management\/utility\/how-to-set-up-a-git-bare-repository-for-code-pushes-in-clustercs\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/clustercs.com\/kb\/docs\/clustercs\/domain-management\/utility\/how-to-set-up-a-git-bare-repository-for-code-pushes-in-clustercs\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/clustercs.com\/kb\/docs\/clustercs\/domain-management\/utility\/how-to-set-up-a-git-bare-repository-for-code-pushes-in-clustercs\/#primaryimage","url":"https:\/\/clustercs.com\/oldkb\/wp-content\/uploads\/2018\/11\/clustercs_domain_listing-1024x663.png","contentUrl":"https:\/\/clustercs.com\/oldkb\/wp-content\/uploads\/2018\/11\/clustercs_domain_listing-1024x663.png"},{"@type":"BreadcrumbList","@id":"https:\/\/clustercs.com\/kb\/docs\/clustercs\/domain-management\/utility\/how-to-set-up-a-git-bare-repository-for-code-pushes-in-clustercs\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/clustercs.com\/kb\/"},{"@type":"ListItem","position":2,"name":"ClusterCS Documentation","item":"https:\/\/clustercs.com\/kb\/docs\/clustercs\/"},{"@type":"ListItem","position":3,"name":"Domain Management","item":"https:\/\/clustercs.com\/kb\/docs\/clustercs\/domain-management\/"},{"@type":"ListItem","position":4,"name":"Utility","item":"https:\/\/clustercs.com\/kb\/docs\/clustercs\/domain-management\/utility\/"},{"@type":"ListItem","position":5,"name":"How to set up a GIT bare repository for code pushes"}]},{"@type":"WebSite","@id":"https:\/\/clustercs.com\/kb\/#website","url":"https:\/\/clustercs.com\/kb\/","name":"ClusterCS Knowledge Base","description":"Welcome to ClusterCS Documentation","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/clustercs.com\/kb\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"acf":[],"_links":{"self":[{"href":"https:\/\/clustercs.com\/kb\/wp-json\/wp\/v2\/docs\/8482","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/clustercs.com\/kb\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/clustercs.com\/kb\/wp-json\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/clustercs.com\/kb\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/clustercs.com\/kb\/wp-json\/wp\/v2\/comments?post=8482"}],"version-history":[{"count":4,"href":"https:\/\/clustercs.com\/kb\/wp-json\/wp\/v2\/docs\/8482\/revisions"}],"predecessor-version":[{"id":8979,"href":"https:\/\/clustercs.com\/kb\/wp-json\/wp\/v2\/docs\/8482\/revisions\/8979"}],"up":[{"embeddable":true,"href":"https:\/\/clustercs.com\/kb\/wp-json\/wp\/v2\/docs\/8476"}],"wp:attachment":[{"href":"https:\/\/clustercs.com\/kb\/wp-json\/wp\/v2\/media?parent=8482"}],"wp:term":[{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/clustercs.com\/kb\/wp-json\/wp\/v2\/doc_tag?post=8482"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}