{"id":46,"date":"2019-08-22T15:47:34","date_gmt":"2019-08-22T15:47:34","guid":{"rendered":"https:\/\/www.techcrm.in\/blogs\/?p=46"},"modified":"2020-09-08T14:55:48","modified_gmt":"2020-09-08T09:25:48","slug":"how-to-deploy-a-website-to-a-remote-server-using-git","status":"publish","type":"post","link":"https:\/\/www.techcrm.in\/blogs\/how-to-deploy-a-website-to-a-remote-server-using-git\/","title":{"rendered":"How to Deploy a Website to a Remote Server Using GIT"},"content":{"rendered":"\n<p> This a step by step tutorial, teaching you how to leverage git to deploy your website to your remote server. It will guide you through each and every step. Familiarity with&nbsp;Git&nbsp;and the&nbsp;Linux Shell&nbsp;are a plus, but not mandatory. <\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"2400\" height=\"1002\" src=\"https:\/\/www.techcrm.in\/blogs\/wp-content\/uploads\/2019\/08\/git-1.png\" alt=\"\" class=\"wp-image-81\"\/><\/figure><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Steps as below<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">1. Login to&nbsp;server<\/h4>\n\n\n\n<p> Open your terminal and login to your server using the following command <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ssh your_user@server_ip_address<\/code><\/pre>\n\n\n\n<p> <\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>replace&nbsp;<em>server_ip_address<\/em>&nbsp;with the actual&nbsp;IP address&nbsp;of your server.<\/li><li>replace&nbsp;<em>your_user&nbsp;<\/em>with the actual username. By default, the username is the same as the host machine, unless you specify a different agent.<\/li><\/ul>\n\n\n\n<p> Insert your password, and  you are now logged to your server. <\/p>\n\n\n\n<h4 class=\"wp-block-heading\">2. Installing GIT<\/h4>\n\n\n\n<p> To install git on your server, copy the following commands one at a time into the terminal and hit&nbsp;<code>Return<\/code>. If prompted, insert your password.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt-get update\nsudo apt-get install git<\/code><\/pre>\n\n\n\n<p> 3. Create a folder for your code to go&nbsp;into<\/p>\n\n\n\n<p> The source code to your website needs to be put somewhere. By convention, code goes inside the&nbsp;<code>\/var\/www<\/code>&nbsp;directory. Navigate there using: <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cd \/var\/www<\/code><\/pre>\n\n\n\n<p> Now, create a new folder to put the source code. For this tutorial, it will be called&nbsp;<em>website_folder.<\/em><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo mkdir website_folder<\/code><\/pre>\n\n\n\n<p> Now, the full path to where you will put your source code is&nbsp;<code>\/var\/www\/website_folder\/<\/code>. It is important to remember this path because you will need it when setting up your git repository. <\/p>\n\n\n\n<h4 class=\"wp-block-heading\">4. Initialise a git repository on your&nbsp;server<\/h4>\n\n\n\n<p> The git repository needs a folder to host it. A good practice is to call that folder website_name.git. Inside of&nbsp;<code>\/var<\/code>, create a folder called&nbsp;<em>repo,&nbsp;<\/em>whichwill contain your git repositories. One of which will be&nbsp;<em>website.git<\/em>. To do so, run the following command: <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo mkdir -p \/var\/repo\/website.git<\/code><\/pre>\n\n\n\n<p> Now, navigate to&nbsp;<code>\/var\/repo\/website.git<\/code>&nbsp;and initialize your git repository: <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cd \/var\/repo\/website.git\/\ngit init --bare<\/code><\/pre>\n\n\n\n<p> Now you have a&nbsp;bare&nbsp;repository for sharing. <\/p>\n\n\n\n<h4 class=\"wp-block-heading\">5. Create&nbsp;Hook<\/h4>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><strong>Note :<\/strong><\/p><cite> A&nbsp;Hook&nbsp;is a program you can place in a hooks directory to trigger actions at certain points in git\u2019s execution. <\/cite><\/blockquote>\n\n\n\n<p> Git has several hooks that it can call after different stages automatically. You will use the&nbsp;<em>post-receive<\/em>&nbsp;hook which is called after your repository has received pushed code. <\/p>\n\n\n\n<p> After initialising your git repository, new folders should appear inside&nbsp;<code>\/var\/repo\/website.git\/<\/code>. Navigate to&nbsp;<em>hooks&nbsp;<\/em>and create a new&nbsp;bash&nbsp;called&nbsp;<em>post-receive<\/em>&nbsp;using your preferred text editor. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cd hooks\nnano post-receive<\/code><\/pre>\n\n\n\n<p> Inside of the newly created file, you need to tell git where to put the files pushed. To do so, paste the following code: <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/sh \ngit --work-tree=path_to_website_folder --git-dir=path_to_git_directory checkout -f name_of_branch<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>replace&nbsp;<em>path_to_website_folder<\/em>&nbsp;with the correct path&nbsp;<code>\/var\/www\/website_folder<\/code>&nbsp;which we created in point 3.<\/li><li>replace&nbsp;<em>path_to_git_directory&nbsp;<\/em>with the path to the bare git repository, which in this case is&nbsp;<code>\/var\/repo\/website.git<\/code>.<\/li><li>name_of_branch is an optional parameter. If not specified, it defaults to&nbsp;<code>master<\/code>.<\/li><\/ul>\n\n\n\n<p> You can follow that script with any other commands of your choice, like restarting the server for instance. <\/p>\n\n\n\n<p>\n\nQuit the editor using&nbsp;<code>ctrl+x<\/code>, and make sure to save the file as&nbsp;<em>post-receive<\/em>.\n\n<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">6. Make the script executable<\/h4>\n\n\n\n<p> In order for the operating system to execute the script, the latter needs to have executable permissions. To do so run the following command: <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>chmod +x post-receive<\/code><\/pre>\n\n\n\n<p> The work on your server is done. You can now logout by simply running&nbsp;<code>logout<\/code> and hitting&nbsp;<code>Return<\/code><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">7. Push local code to the&nbsp;server<\/h4>\n\n\n\n<p> From your terminal, navigate to your local folder, and if it is not already a working git repository, initialise it as one. Then in order to configure git to push code to the remote server, you need to point it to its address. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git init\ngit remote add name_of_repository ssh:\/\/your_user@server_ip_address\/path_to_git_directory<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li><em>name_of_repository<\/em>&nbsp;can be any name you want. It is the name of the remote repository.<\/li><li>replace&nbsp;<em>server_ip_address<\/em>&nbsp;with the actual&nbsp;IP address&nbsp;of your server.<\/li><li>replace&nbsp;<em>your_user&nbsp;<\/em>with the actual username. By default, the username is&nbsp;root.<\/li><li>replace&nbsp;<em>path_to_git_directory&nbsp;<\/em>with the path to the bare git repository, which in this case is&nbsp;<code>var\/repo\/website.git\/<\/code>.<\/li><\/ul>\n\n\n\n<p> Now, to push code to your remote server just run from inside your local git repository the following command: <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git push name_of_repository name_of_branch<\/code><\/pre>\n\n\n\n<p> Enter your password, and now your code is live and should be found inside of\u00a0<code>\/var\/www\/website_folder<\/code><\/p>\n\n\n\n<p>\n\nHope you find this blog post helpful.<\/p>\n\n\n\n<p>Feel free to add comments and queries, that helps us to improve the quality of posts.<\/p>\n\n\n\n<p>You can contact us at&nbsp;<a rel=\"noreferrer noopener\" href=\"mailto:contact@urdhva-tech.com\" target=\"_blank\">info@techcrm.in<\/a><\/p>\n\n\n\n<p>Thank you.\n\n<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This a step by step tutorial, teaching you how to leverage git to deploy your website to your remote server. It will guide you through each and every step. Familiarity with&nbsp;Git&nbsp;and the&nbsp;Linux Shell&nbsp;are a plus, but not mandatory. Steps as below 1. Login to&nbsp;server Open your terminal and login to your server using the following [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[5],"class_list":["post-46","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-git"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Deploy a Website to a Remote Server Using GIT - TechCRM<\/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:\/\/www.techcrm.in\/blogs\/how-to-deploy-a-website-to-a-remote-server-using-git\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Deploy a Website to a Remote Server Using GIT - TechCRM\" \/>\n<meta property=\"og:description\" content=\"This a step by step tutorial, teaching you how to leverage git to deploy your website to your remote server. It will guide you through each and every step. Familiarity with&nbsp;Git&nbsp;and the&nbsp;Linux Shell&nbsp;are a plus, but not mandatory. Steps as below 1. Login to&nbsp;server Open your terminal and login to your server using the following [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.techcrm.in\/blogs\/how-to-deploy-a-website-to-a-remote-server-using-git\/\" \/>\n<meta property=\"og:site_name\" content=\"TechCRM\" \/>\n<meta property=\"article:published_time\" content=\"2019-08-22T15:47:34+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-09-08T09:25:48+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.techcrm.in\/blogs\/wp-content\/uploads\/2019\/08\/git-1.png\" \/>\n<meta name=\"author\" content=\"Navin Rakhonde\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Navin Rakhonde\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.techcrm.in\/blogs\/how-to-deploy-a-website-to-a-remote-server-using-git\/\",\"url\":\"https:\/\/www.techcrm.in\/blogs\/how-to-deploy-a-website-to-a-remote-server-using-git\/\",\"name\":\"How to Deploy a Website to a Remote Server Using GIT - TechCRM\",\"isPartOf\":{\"@id\":\"https:\/\/www.techcrm.in\/blogs\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.techcrm.in\/blogs\/how-to-deploy-a-website-to-a-remote-server-using-git\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.techcrm.in\/blogs\/how-to-deploy-a-website-to-a-remote-server-using-git\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.techcrm.in\/blogs\/wp-content\/uploads\/2019\/08\/git-1.png\",\"datePublished\":\"2019-08-22T15:47:34+00:00\",\"dateModified\":\"2020-09-08T09:25:48+00:00\",\"author\":{\"@id\":\"https:\/\/www.techcrm.in\/blogs\/#\/schema\/person\/992dfe427bb53dcdfd72dd80e3ef9dbc\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.techcrm.in\/blogs\/how-to-deploy-a-website-to-a-remote-server-using-git\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.techcrm.in\/blogs\/how-to-deploy-a-website-to-a-remote-server-using-git\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.techcrm.in\/blogs\/how-to-deploy-a-website-to-a-remote-server-using-git\/#primaryimage\",\"url\":\"https:\/\/www.techcrm.in\/blogs\/wp-content\/uploads\/2019\/08\/git-1.png\",\"contentUrl\":\"https:\/\/www.techcrm.in\/blogs\/wp-content\/uploads\/2019\/08\/git-1.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.techcrm.in\/blogs\/how-to-deploy-a-website-to-a-remote-server-using-git\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.techcrm.in\/blogs\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Uncategorized\",\"item\":\"https:\/\/www.techcrm.in\/blogs\/category\/uncategorized\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"How to Deploy a Website to a Remote Server Using GIT\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.techcrm.in\/blogs\/#website\",\"url\":\"https:\/\/www.techcrm.in\/blogs\/\",\"name\":\"TechCRM\",\"description\":\"Blog\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.techcrm.in\/blogs\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.techcrm.in\/blogs\/#\/schema\/person\/992dfe427bb53dcdfd72dd80e3ef9dbc\",\"name\":\"Navin Rakhonde\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.techcrm.in\/blogs\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/9cc8fd1b948255055b85e5d41dabfc6e704f806d180a1e21cb8fb378e2f5c022?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/9cc8fd1b948255055b85e5d41dabfc6e704f806d180a1e21cb8fb378e2f5c022?s=96&d=mm&r=g\",\"caption\":\"Navin Rakhonde\"},\"sameAs\":[\"https:\/\/www.techcrm.in\/\"],\"url\":\"https:\/\/www.techcrm.in\/blogs\/author\/navin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Deploy a Website to a Remote Server Using GIT - TechCRM","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:\/\/www.techcrm.in\/blogs\/how-to-deploy-a-website-to-a-remote-server-using-git\/","og_locale":"en_US","og_type":"article","og_title":"How to Deploy a Website to a Remote Server Using GIT - TechCRM","og_description":"This a step by step tutorial, teaching you how to leverage git to deploy your website to your remote server. It will guide you through each and every step. Familiarity with&nbsp;Git&nbsp;and the&nbsp;Linux Shell&nbsp;are a plus, but not mandatory. Steps as below 1. Login to&nbsp;server Open your terminal and login to your server using the following [&hellip;]","og_url":"https:\/\/www.techcrm.in\/blogs\/how-to-deploy-a-website-to-a-remote-server-using-git\/","og_site_name":"TechCRM","article_published_time":"2019-08-22T15:47:34+00:00","article_modified_time":"2020-09-08T09:25:48+00:00","og_image":[{"url":"https:\/\/www.techcrm.in\/blogs\/wp-content\/uploads\/2019\/08\/git-1.png"}],"author":"Navin Rakhonde","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Navin Rakhonde","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.techcrm.in\/blogs\/how-to-deploy-a-website-to-a-remote-server-using-git\/","url":"https:\/\/www.techcrm.in\/blogs\/how-to-deploy-a-website-to-a-remote-server-using-git\/","name":"How to Deploy a Website to a Remote Server Using GIT - TechCRM","isPartOf":{"@id":"https:\/\/www.techcrm.in\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.techcrm.in\/blogs\/how-to-deploy-a-website-to-a-remote-server-using-git\/#primaryimage"},"image":{"@id":"https:\/\/www.techcrm.in\/blogs\/how-to-deploy-a-website-to-a-remote-server-using-git\/#primaryimage"},"thumbnailUrl":"https:\/\/www.techcrm.in\/blogs\/wp-content\/uploads\/2019\/08\/git-1.png","datePublished":"2019-08-22T15:47:34+00:00","dateModified":"2020-09-08T09:25:48+00:00","author":{"@id":"https:\/\/www.techcrm.in\/blogs\/#\/schema\/person\/992dfe427bb53dcdfd72dd80e3ef9dbc"},"breadcrumb":{"@id":"https:\/\/www.techcrm.in\/blogs\/how-to-deploy-a-website-to-a-remote-server-using-git\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.techcrm.in\/blogs\/how-to-deploy-a-website-to-a-remote-server-using-git\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.techcrm.in\/blogs\/how-to-deploy-a-website-to-a-remote-server-using-git\/#primaryimage","url":"https:\/\/www.techcrm.in\/blogs\/wp-content\/uploads\/2019\/08\/git-1.png","contentUrl":"https:\/\/www.techcrm.in\/blogs\/wp-content\/uploads\/2019\/08\/git-1.png"},{"@type":"BreadcrumbList","@id":"https:\/\/www.techcrm.in\/blogs\/how-to-deploy-a-website-to-a-remote-server-using-git\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.techcrm.in\/blogs\/"},{"@type":"ListItem","position":2,"name":"Uncategorized","item":"https:\/\/www.techcrm.in\/blogs\/category\/uncategorized\/"},{"@type":"ListItem","position":3,"name":"How to Deploy a Website to a Remote Server Using GIT"}]},{"@type":"WebSite","@id":"https:\/\/www.techcrm.in\/blogs\/#website","url":"https:\/\/www.techcrm.in\/blogs\/","name":"TechCRM","description":"Blog","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.techcrm.in\/blogs\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.techcrm.in\/blogs\/#\/schema\/person\/992dfe427bb53dcdfd72dd80e3ef9dbc","name":"Navin Rakhonde","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.techcrm.in\/blogs\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/9cc8fd1b948255055b85e5d41dabfc6e704f806d180a1e21cb8fb378e2f5c022?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/9cc8fd1b948255055b85e5d41dabfc6e704f806d180a1e21cb8fb378e2f5c022?s=96&d=mm&r=g","caption":"Navin Rakhonde"},"sameAs":["https:\/\/www.techcrm.in\/"],"url":"https:\/\/www.techcrm.in\/blogs\/author\/navin\/"}]}},"_links":{"self":[{"href":"https:\/\/www.techcrm.in\/blogs\/wp-json\/wp\/v2\/posts\/46","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.techcrm.in\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.techcrm.in\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.techcrm.in\/blogs\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.techcrm.in\/blogs\/wp-json\/wp\/v2\/comments?post=46"}],"version-history":[{"count":9,"href":"https:\/\/www.techcrm.in\/blogs\/wp-json\/wp\/v2\/posts\/46\/revisions"}],"predecessor-version":[{"id":103,"href":"https:\/\/www.techcrm.in\/blogs\/wp-json\/wp\/v2\/posts\/46\/revisions\/103"}],"wp:attachment":[{"href":"https:\/\/www.techcrm.in\/blogs\/wp-json\/wp\/v2\/media?parent=46"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.techcrm.in\/blogs\/wp-json\/wp\/v2\/categories?post=46"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.techcrm.in\/blogs\/wp-json\/wp\/v2\/tags?post=46"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}