{"id":623,"date":"2021-07-23T12:34:14","date_gmt":"2021-07-23T12:34:14","guid":{"rendered":"https:\/\/ssdsunucum.com\/blog\/guide-to-git-deployment\/"},"modified":"2021-07-23T12:34:14","modified_gmt":"2021-07-23T12:34:14","slug":"guide-to-git-deployment","status":"publish","type":"post","link":"https:\/\/ssdsunucum.com\/blog\/guide-to-git-deployment\/","title":{"rendered":"Guide to Git\u2122 &#8211; Deployment"},"content":{"rendered":"<\/p>\n<div class=\"col-md-9\">\n<div class=\"flex-column flex-md-row article-header\"><\/div>\n<hr>\n<h2 id=\"overview\">Overview<\/h2>\n<p>The <em>Git\u2122 Version Control<\/em> feature allows you to deploy your cPanel-managed repositories. Generally, deployment sends finished code into production. You can use different configurations to automatically (push deployment) or manually (pull deployment) deploy changes.<\/p>\n<ul>\n<li>For example, you could use deployment to make changes to your website locally. Then, automatically send them to a directory on your cPanel account.<\/li>\n<li>For more information about how to deploy changes, read our <em>Git\u2122 Version Control<\/em> documentation.<\/li>\n<li>For more information about how to troubleshoot problems with this feature, read our Guide to Git &#8211; For System Administrators documentation.<\/li>\n<li>For more information about Git commands, such as <code>git push<\/code>, <code>git pull<\/code>, or <code>git commit<\/code>, read our Guide to Git\u2122 &#8211; Common Git Commands documentation.<\/li>\n<\/ul>\n<h2 id=\"requirements\">Requirements<\/h2>\n<p>Before deployment, repositories <strong>must<\/strong> meet the following requirements:<\/p>\n<ul>\n<li>A valid checked-in <code>.cpanel.yml<\/code> file in the top-level directory.<\/li>\n<li>One or more local or remote branches.<\/li>\n<li>A clean working tree.<\/li>\n<\/ul>\n<p>If a repository does <strong>not<\/strong> meet these requirements, the system will <strong>not<\/strong> display deployment information. Also, it will disable deployment functionality.<\/p>\n<h2 id=\"the-deployment-yaml-file\">The deployment YAML file<\/h2>\n<p>The <code>.cpanel.yml<\/code> file determines how and where the changed files deploy. You must check a <code>.cpanel.yml<\/code> file in to the top-level directory for each cPanel-managed repository that you deploy. The <code>.cpanel.yml<\/code> files must use the format in the examples below.<\/p>\n<div class=\"callout callout-warning\">\n<div class=\"callout-heading\">Important:<\/div>\n<div class=\"callout-content\">\n<ul>\n<li>The files below are only <strong>examples<\/strong>. You <strong>must<\/strong> update them to suit your needs. These files will not allow you to deploy a repository successfully.<\/li>\n<li><strong>Don\u2019t<\/strong> use a wildcard character, such as an asterisk, to deploy all files. This could deploy items like the <code>.git<\/code> directory and cause serious problems.<\/li>\n<li><strong>Don\u2019t<\/strong> use characters that are invalid in YAML files. For more information, read the Escaped Characters section of yaml.org\u2019s YAML Specification.<\/li>\n<\/ul><\/div>\n<\/div>\n<h3 id=\"deploy-individual-files\">Deploy individual files<\/h3>\n<p>The following <code>.cpanel.yml<\/code> file deploys the <code>index.html<\/code> and <code>style.css<\/code> files to the <code>example<\/code> account\u2019s <code>public_html<\/code> directory:<\/p>\n<div class=\"highlight\">\n<div style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\">\n<table style=\"border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;\">\n<tr>\n<td style=\"vertical-align:top;padding:0;margin:0;border:0;\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-perl\" data-lang=\"perl\"><span style=\"margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\">1\n<\/span><span style=\"margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\">2\n<\/span><span style=\"margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\">3\n<\/span><span style=\"margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\">4\n<\/span><span style=\"margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\">5\n<\/span><span style=\"margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\">6\n<\/span><\/code><\/pre>\n<\/td>\n<td style=\"vertical-align:top;padding:0;margin:0;border:0;;width:100%\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-perl\" data-lang=\"perl\"><span style=\"color:#f92672\">---<\/span>\ndeployment:\n  tasks:\n    <span style=\"color:#f92672\">-<\/span> export DEPLOYPATH<span style=\"color:#f92672\">=<\/span><span style=\"color:#e6db74\">\/home\/<\/span>user<span style=\"color:#e6db74\">\/public_html\/<\/span>\n    <span style=\"color:#f92672\">-<\/span> <span style=\"color:#e6db74\">\/bin\/c<\/span>p index<span style=\"color:#f92672\">.<\/span>html $DEPLOYPATH\n    <span style=\"color:#f92672\">-<\/span> <span style=\"color:#e6db74\">\/bin\/c<\/span>p style<span style=\"color:#f92672\">.<\/span>css $DEPLOYPATH<\/code><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n<\/div>\n<\/div>\n<ul>\n<li>Line 1 is the beginning of a YAML file.<\/li>\n<li>Lines 2 and 3 add the <code>deployment<\/code> and <code>tasks<\/code> keys, respectively.<\/li>\n<li>Lines 4 through 6 specify an array of BASH commands to run during deployment. You can add as many commands to this array as you wish.<\/li>\n<\/ul>\n<div class=\"callout callout-info\">\n<div class=\"callout-heading\">Note:<\/div>\n<div class=\"callout-content\">\n<p>To add comments to this file, add a line that begins with the hash character (<code>#<\/code>).<\/p>\n<\/p><\/div>\n<\/div>\n<h3 id=\"deploy-an-entire-directory\">Deploy an entire directory<\/h3>\n<p>The following <code>.cpanel.yml<\/code> file copies the <code>images<\/code> directory and all of its contents to the <code>example<\/code> account\u2019s <code>public_html<\/code> directory:\n<\/p>\n<div class=\"highlight\">\n<div style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\">\n<table style=\"border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;\">\n<tr>\n<td style=\"vertical-align:top;padding:0;margin:0;border:0;\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-perl\" data-lang=\"perl\"><span style=\"margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\">1\n<\/span><span style=\"margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\">2\n<\/span><span style=\"margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\">3\n<\/span><span style=\"margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\">4\n<\/span><span style=\"margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\">5\n<\/span><\/code><\/pre>\n<\/td>\n<td style=\"vertical-align:top;padding:0;margin:0;border:0;;width:100%\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-perl\" data-lang=\"perl\"><span style=\"color:#f92672\">---<\/span>\ndeployment:\n  tasks:\n    <span style=\"color:#f92672\">-<\/span> export DEPLOYPATH<span style=\"color:#f92672\">=<\/span><span style=\"color:#e6db74\">\/home\/<\/span>example<span style=\"color:#e6db74\">\/public_html\/<\/span>\n    <span style=\"color:#f92672\">-<\/span> <span style=\"color:#e6db74\">\/bin\/c<\/span>p <span style=\"color:#f92672\">-<\/span>R images $DEPLOYPATH<\/code><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n<\/div>\n<\/div>\n<ul>\n<li>Line 1 is the beginning of a YAML file.<\/li>\n<li>Lines 2 and 3 add the <code>deployment<\/code> and <code>tasks<\/code> keys, respectively.<\/li>\n<li>Lines 4 and 5 specify an array of BASH commands to run during deployment. You can add as many commands to this array as you wish.<\/li>\n<\/ul>\n<div class=\"callout callout-info\">\n<div class=\"callout-heading\">Note:<\/div>\n<div class=\"callout-content\">\n<p>To add comments to this file, add a line that begins with the hash character (<code>#<\/code>).<\/p>\n<\/p><\/div>\n<\/div>\n<h2 id=\"automatic-or-push-deployment\">Automatic or push deployment<\/h2>\n<div class=\"callout callout-warning\">\n<div class=\"callout-heading\">Important:<\/div>\n<div class=\"callout-content\">\n<p>cPanel\u2019s <em>Git\u2122 Version Control<\/em> interface (<em>cPanel &gt;&gt; Home &gt;&gt; Files &gt;&gt; Git Version Control<\/em>) automatically adds a post-receive hook to all cPanel-managed repositories.<\/p>\n<ul>\n<li>When you push changes directly to a cPanel-managed repository that includes a <code>.cpanel.yml<\/code> file, the hook deploys those changes automatically.<\/li>\n<li>For more information, read Git\u2019s githooks documentation.<\/li>\n<\/ul><\/div>\n<\/div>\n<p><center><\/p>\n<figure>\n    <img src=\"https:\/\/ssdsunucum.com\/blog\/wp-content\/uploads\/2021\/07\/git-push-deployment-workflow.png\" title=\"git-push-deployment-workflow\"><br \/>\n<\/figure>\n<\/p>\n<p><\/center><\/p>\n<p>With push deployment, a single <code>git push<\/code> command sends changes from your local computer to your cPanel-managed repository. The system then automatically runs the commands in your <code>.cpanel.yml<\/code> file. This configuration will send changes from the cPanel-managed repository to a production directory. (For example, to the directory that contains your website\u2019s public files.)<\/p>\n<div class=\"callout callout-info\">\n<div class=\"callout-heading\">Note:<\/div>\n<div class=\"callout-content\">\n<p>You can use manual deployment to deploy your repository again without new changes.<\/p>\n<\/p><\/div>\n<\/div>\n<h2 id=\"manual-or-pull-deployment\">Manual or pull deployment<\/h2>\n<\/p>\n<p><center><\/p>\n<figure>\n    <img src=\"https:\/\/ssdsunucum.com\/blog\/wp-content\/uploads\/2021\/07\/git-pull-deployment-workflow.png\" title=\"git-pull-deployment-workflow\"><br \/>\n<\/figure>\n<\/p>\n<p><\/center><\/p>\n<p>With pull deployment, the <code>git push<\/code> command sends changes from your local computer to a remote repository.<\/p>\n<ul>\n<li>\n<p>When you click <em>Update from Remote<\/em> in the <em>Pull or Deploy<\/em> tab of the <em>Manage<\/em> section of cPanel\u2019s <em>Git\u2122 Version Control<\/em> interface (<em>cPanel &gt;&gt; Home &gt;&gt; Files &gt;&gt; Git Version Control<\/em>), the system retrieves changes from the remote repository and applies them to the cPanel-managed repository.<\/p>\n<\/li>\n<li>\n<p>When you click <em>Deploy HEAD Commit<\/em>, the system runs the commands in your <code>.cpanel.yml<\/code> file to send changes from the cPanel-managed repository to a production directory. (For example, to the directory that contains your website\u2019s public files.)<\/p>\n<\/li>\n<\/ul><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Overview The Git\u2122 Version Control feature allows you to deploy your cPanel-managed repositories. Generally, deployment sends finished code into production. You can use different configurations to automatically (push deployment) or manually (pull deployment) deploy changes. For example, you could use deployment to make changes to your website locally. Then, automatically send them to a directory &hellip;<\/p>\n","protected":false},"author":1,"featured_media":624,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/ssdsunucum.com\/blog\/wp-json\/wp\/v2\/posts\/623"}],"collection":[{"href":"https:\/\/ssdsunucum.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ssdsunucum.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ssdsunucum.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ssdsunucum.com\/blog\/wp-json\/wp\/v2\/comments?post=623"}],"version-history":[{"count":0,"href":"https:\/\/ssdsunucum.com\/blog\/wp-json\/wp\/v2\/posts\/623\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ssdsunucum.com\/blog\/wp-json\/wp\/v2\/media\/624"}],"wp:attachment":[{"href":"https:\/\/ssdsunucum.com\/blog\/wp-json\/wp\/v2\/media?parent=623"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ssdsunucum.com\/blog\/wp-json\/wp\/v2\/categories?post=623"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ssdsunucum.com\/blog\/wp-json\/wp\/v2\/tags?post=623"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}