{"id":320196,"date":"2021-08-09T19:00:00","date_gmt":"2021-08-09T16:00:00","guid":{"rendered":"https:\/\/en.buradabiliyorum.com\/how-to-set-up-a-private-git-server-cloudsavvy-it\/"},"modified":"2021-08-09T19:00:00","modified_gmt":"2021-08-09T16:00:00","slug":"how-to-set-up-a-private-git-server-cloudsavvy-it","status":"publish","type":"post","link":"https:\/\/buradabiliyorum.com\/en\/how-to-set-up-a-private-git-server-cloudsavvy-it\/","title":{"rendered":"#How to Set Up a Private Git Server \u2013 CloudSavvy IT"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_85 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a405eb78dd2d\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #dd3333;color:#dd3333\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #dd3333;color:#dd3333\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a405eb78dd2d\" checked aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-set-up-a-private-git-server-cloudsavvy-it\/#Why_Run_Your_Own_Server\" >Why Run Your Own Server?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-set-up-a-private-git-server-cloudsavvy-it\/#Git_Remotes_Are_Just_Someone_Elses_Repository\" >Git Remotes Are Just Someone Else\u2019s Repository<\/a><\/li><\/ul><\/nav><\/div>\n<p><strong>&#8220;#How to Set Up a Private Git Server \u2013 CloudSavvy IT&#8221;<\/strong><\/p>\n<div id=\"article-content-area\">\n<img loading=\"lazy\" decoding=\"async\" class=\"type:primaryImage alignnone wp-image-2266 size-full\" srcset=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2019\/10\/e713ed70-1.png?width=398&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1 400w, https:\/\/www.cloudsavvyit.com\/p\/uploads\/2019\/10\/e713ed70-1.png?width=1198&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1 1200w\" sizes=\"auto, 400w, 1200w\" src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2019\/10\/e713ed70-1.png?width=1198&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Git logo\" width=\"700\" height=\"299\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>If you want to set up source control for a project, but prefer not to host it on a service like GitHub, you can run your own <code>git<\/code>\u00a0server on a VPS to store your code and act as a master repository for any collaborators.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Why_Run_Your_Own_Server\"><\/span>Why Run Your Own Server?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>With how many free\u00a0hosted <code>git<\/code>\u00a0providers there are, such as <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/github.com\/\">GitHub<\/a>, <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/about.gitlab.com\/\">GitLab<\/a>, and <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/bitbucket.org\/\">Bitbucket<\/a>, it doesn\u2019t make much sense to do it yourself. But, there are a few situations where it\u2019s a viable solution.<\/p>\n<p>First off, running your own server is far more private, especially if you\u2019re working on code you\u2019d rather not store on someone else\u2019s \u201ccloud.\u201d This isn\u2019t to say providers like GitLab aren\u2019t secure, but hosting everything yourself may give some people more peace of mind.<\/p>\n<p>Also, if you\u2019re using a third-party service, there are restrictions on file size that may not be ideal. GitHub does not allow files over 100 MB, which can be a major problem for projects with large binary files. Using your own server removes this limit, assuming you can pay for more hard drive space.<\/p>\n<p>Whatever your use case is, you probably can do better than barebones <code>git<\/code>. GitLab\u2019s <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/about.gitlab.com\/install\/\">Community Edition<\/a> is free and open source, and is easy to set up on your own server. This gives you all the benefits of hosting it yourself along with a very nice web interface and numerous CI\/CD tools. We highly recommend you use GitLab if you have spare server space. (It does require around 3 GB of RAM.) You can read our guide to installing and configuring it\u00a0to learn more.<\/p>\n<p>But, if you don\u2019t want all the bells and whistles, and just want to run a simple <code>git<\/code>\u00a0remote, you can continue reading.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Git_Remotes_Are_Just_Someone_Elses_Repository\"><\/span>Git Remotes Are Just Someone Else\u2019s Repository<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The first thing to note about <code>git<\/code>\u00a0is that hosting a server isn\u2019t actually very complicated. Git uses a distributed source control model; your local clone of a repository doesn\u2019t connect to all of your coworkers at all, but it does connect to a \u201cremote,\u201d usually on an external central server or service. When you push and pull, you make modifications to the remote\u2019s official master copy. When your coworkers fetch from the remote, they <a href=\"https:\/\/buradabiliyorum.com\/en\/category\/download-scripts-themes-apps\/\" data-internallinksmanager029f6b8e52c=\"9\" title=\"Download Scripts &amp; Themes &amp; Apps\" target=\"_blank\" rel=\"noopener\">download<\/a> your commits.<\/p>\n<p>You can technically run <code>git<\/code>\u00a0as a completely decentralized service. If you had two people, they\u2019d each pull updates from each other. (Pushing to non-server repositories isn\u2019t advised in this setup.) This isn\u2019t really usable in practice, unless both parties have static IP addresses and are always online, so most people opt for the server-client model.<\/p>\n<p>So, all that a <code>git<\/code>\u00a0server is then is just a regular repository that\u2019s configured as the master copy and open to the internet. It\u2019s surprisingly simple to set up. First, we\u2019ll need to create a new user.\u00a0Git uses SSH for authentication and all traffic between servers and clients, so we\u2019ll need a service user to manage the repo.<\/p>\n<pre>sudo useradd git<\/pre>\n<p>Next, switch to the <code>git<\/code>\u00a0user for the rest of the setup:<\/p>\n<pre>su git<\/pre>\n<p>You\u2019ll need to add your SSH keys to the <code>git<\/code>\u00a0user\u2019s <code>authorized_keys<\/code>\u00a0file:<\/p>\n<pre>nano ~\/.ssh\/authorized_keys<\/pre>\n<p>This is one area where services like GitHub and GitLab have command line Git beat. Access management isn\u2019t easily handled this way, as you\u2019ll need to give everyone access to the same service user, which isn\u2019t ideal, or you\u2019ll need to set up separate users for each person, which also isn\u2019t ideal. Either way, commits will show up with whatever username and email the end user has configured in their <code>git<\/code>\u00a0settings.<\/p>\n<p>Anyway, to create the actual repository, simply run <code>git init<\/code>\u00a0in the <code>git<\/code>\u00a0user\u2019s home directory:<\/p>\n<pre>git init --bare repository.git<\/pre>\n<p>The <code>--bare<\/code>\u00a0option is necessary here. Usually, when you\u2019re cloning a repository, <code>git<\/code>\u00a0stores all of the files it uses to manage versions in the hidden\u00a0<code>.git<\/code>\u00a0folder, and it keeps a usable version of wherever your currently checked out HEAD is at. This usually makes your repo folder about twice as big as it would be without <code>git<\/code>, though it can be larger if you have large binary files and a lot of changes over time.<\/p>\n<p>A bare repository is simply a repo without the usable versions of the currently checked out files. Instead, the repository folder is just the contents of what would be the <code>.git<\/code>\u00a0folder. This saves storage space, and configures the repository as a master server. Because there\u2019s no local content, there will be no conflicts with the branch HEAD. It\u2019s convention to name bare repositories with the <code>.git<\/code>\u00a0file extension, but it isn\u2019t explicitly required.<\/p>\n<p>That\u2019s all that is required on the server side. From your local machine, you\u2019ll need to clone the repo or add a new remote:<\/p>\n<pre>git remote add origin git@example.com:repository.git<\/pre>\n<p>The URL starts with <code>git@<\/code>\u00a0because it\u2019s connecting over SSH as the <code>git<\/code>\u00a0user. The <code>:repository.git<\/code>\u00a0on the end is actually a path name, not just an identifier. The path is relative to the <code>git<\/code>\u00a0user\u2019s home directory, so if you placed the repo somewhere else, you\u2019ll want to move it here or use the full pathname.<\/p>\n<p>After you\u2019ve connected your local repo, you should have full access to push and pull as normal. Keep in mind though that default <code>git<\/code>\u00a0has no built permissions system, so there\u2019s nothing preventing anyone with access to the <code>git<\/code>\u00a0user from having full control over your master repository.\n<\/div>\n<blockquote><p><strong><span style=\"color: #ff6600;\">If you liked the article, do not forget to share it with your friends. Follow us on\u00a0<span style=\"color: #ff0000;\"><a style=\"color: #ff0000;\" href=\"https:\/\/news.google.com\/publications\/CAAqBwgKMLG0nwswvr63Aw\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Google News<\/a><\/span>\u00a0too, click on the star and choose us from your favorites.<\/span><\/strong><\/p><\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\">For forums sites go to <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/forum.buradabiliyorum.com\/\" target=\"_blank\" rel=\"noopener\">Forum.BuradaBiliyorum.Com<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\"><strong>If you want to read more like this article, you can visit our <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/en.buradabiliyorum.com\/technology\/\" target=\"_blank\" rel=\"noopener\">Technology category.<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<p><span style=\"color: black;\"><a style=\"color: #ff9900;\" href=\"https:\/\/www.cloudsavvyit.com\/2510\/how-to-set-up-a-private-git-server\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;#How to Set Up a Private Git Server \u2013 CloudSavvy IT&#8221; If you want to set up source control for a project, but prefer not to host it on a service like GitHub, you can run your own git\u00a0server on a VPS to store your code and act as a master repository for any collaborators&#8230;.<\/p>\n","protected":false},"author":1,"featured_media":320197,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2019\/10\/e713ed70-1.png","fifu_image_alt":"","footnotes":""},"categories":[18],"tags":[],"class_list":["post-320196","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology"],"_links":{"self":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/320196","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/comments?post=320196"}],"version-history":[{"count":0,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/320196\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media\/320197"}],"wp:attachment":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media?parent=320196"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/categories?post=320196"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/tags?post=320196"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}