{"id":1306,"date":"2014-04-22T16:00:25","date_gmt":"2014-04-22T14:00:25","guid":{"rendered":"http:\/\/blog.eweibel.net\/?p=1306"},"modified":"2014-04-22T19:20:54","modified_gmt":"2014-04-22T17:20:54","slug":"build-your-private-git-infrastructure","status":"publish","type":"post","link":"https:\/\/blog.eweibel.net\/?p=1306","title":{"rendered":"Build your private git infrastructure"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/blog.eweibel.net\/wp-content\/uploads\/gitlogo.png\" alt=\"gitlogo\" width=\"220\" height=\"92\" class=\"alignright size-full wp-image-1332\" \/>I&#8217;ve got for several years a virtual server to put my own projects under version control. I started with <a href=\"http:\/\/www.nongnu.org\/cvs\/\" target=\"_blank\">CVS<\/a>, then migrated to <a href=\"http:\/\/subversion.tigris.org\/\" target=\"_blank\">SVN<\/a> and now I&#8217;m start thinking to migrate all the old projects to <a href=\"http:\/\/git-scm.com\/\" target=\"_blank\">git<\/a>. This because I like git very much and I use it personally for several years now.<br \/>\nThe first question but was: <a href=\"http:\/\/en.wikipedia.org\/wiki\/Not_invented_here\" target=\"_blank\">&#8220;Not invented here&#8221;-syndrom<\/a>? Why not using <a href=\"https:\/\/github.com\/\" target=\"_blank\">github<\/a> or <a href=\"https:\/\/www.codeplex.com\/\" target=\"_blank\">codeplex<\/a> or any other public platform which offers git support. Well, some of my own little projects are just not worth it to publish or some of them are not meant to be published. So still existing the question why not buy a private account at github or somewhere else. At this point I was much more interested to see how hard it is to build your own little github environment. So, the requirements are:<\/p>\n<ul>\n<li>remote repository for git vcs<\/li>\n<li>simple user management<\/li>\n<li>website to browse the repositories<\/li>\n<\/ul>\n<p>Fortunately the documentation for git is currently very good, specially <a href=\"http:\/\/git-scm.com\/book\/en\/Git-on-the-Server\" target=\"_blank\">this site<\/a> helps a lot.\n<\/p>\n<p><strong>Setup a new repository on the server<\/strong><\/p>\n<p>First you need of course git installed on your server. The second important thing is to add a new user &#8220;git&#8221;. You can add the user by command line or through your preferred tool, like <a href=\"www.webmin.com\" target=\"_blank\">webmin<\/a>. The user git is just a service account and it should not be allowed to log in with this account. So therefore just change the shell to &#8220;\/usr\/bin\/git-shell&#8221;.<\/p>\n<p>To push some changes to my git-server, I need to initialize the repository on the server. It is a <a href=\"http:\/\/git-scm.com\/book\/en\/Git-on-the-Server-Getting-Git-on-a-Server\" target=\"_blank\">convention<\/a> that the directory name of a <a href=\"http:\/\/www.saintsjd.com\/2011\/01\/what-is-a-bare-git-repository\/\" target=\"_blank\">bare-repository<\/a> has the suffix &#8220;.git&#8221;. So the command looks like this:<\/p>\n<pre class=\"brush: bash\">git init --bare Project.git<\/pre>\n<p>After that I updated the rights for the created directory:<\/p>\n<pre class=\"brush: bash\">chown -R git.users Project.git<\/pre>\n<\/p>\n<p><strong>Authentication<\/strong><\/p>\n<p>I decided to use the simplest way to communicate with the remote repositories which is by <a href=\"http:\/\/git-scm.com\/book\/en\/Git-on-the-Server-Setting-Up-the-Server\" target=\"_blank\">ssh<\/a>. To add a new user, you must have his public key (<a href=\"https:\/\/help.github.com\/articles\/generating-ssh-keys\" target=\"_blank\">here<\/a> a short documentation how to generate a new public key). When you received the public key of a new user, it is easy to add it to the allowed users:<\/p>\n<pre class=\"brush: bash\">cat publickey_id_rsa.pub >> home\/git\/.ssh\/autorized_keys<\/pre>\n<\/p>\n<p><strong>Browse the git repositories<\/strong><\/p>\n<p>The next step was to fulfil the website requirement. I chose <a href=\"https:\/\/git.wiki.kernel.org\/index.php\/Gitweb\" target=\"_blank\">gitweb<\/a>, which is just good enough to start and it fulfils my current needs. On my linux (debian) machine, it was an easy task:<\/p>\n<pre class=\"brush: bash\">apt-get install gitweb<\/pre>\n<p>Also the configuration of gitweb was really easy. First I defined a root directory, where I plan to store all my git repositories. This directory I had to specify in the configuration file \/etc\/gitweb.conf:<\/p>\n<pre class=\"brush: bash\">$projectroot = \"\/vcs\/git\";<\/pre>\n<p>The last step was to protect the gitweb site with <a href=\"http:\/\/httpd.apache.org\/docs\/2.2\/howto\/auth.html\" target=\"_blank\">basic authentication<\/a> (I use an apache web server, so the following lines are in the configuration file of the gitweb site):<\/p>\n<pre class=\"brush: bash\">\r\nAuthType Basic\r\nAuthName \"gitweb\"\r\nAuthUserFile \/www\/gitweb.example.com\/auth.db\r\nrequire valid-user\r\n<\/pre>\n<p>Finally I added the allowed users in the auth.db file.<\/p>\n<p><strong>Using the remote repository<\/strong><\/p>\n<p>The easiest case is to clone the remote repository:<\/p>\n<pre class=\"brush: bash\">git clone git@example.com:\/vcs\/git\/Project.git Project<\/pre>\n<p>Another way is to add the remote repository to an existing git repository:<\/p>\n<pre class=\"brush: bash\">git remote add origin git@example.com:\/vcs\/git\/Project.git<\/pre>\n<p>To get the latest changes from the remote repository you&#8217;ll use the command<\/p>\n<pre class=\"brush: bash\">git pull origin master<\/pre>\n<p>To save the local changes in the remote repository you&#8217;ll use the command<\/p>\n<pre class=\"brush: bash\">git push origin master<\/pre><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve got for several years a virtual server to put my own projects under version control. I started with CVS, then migrated to SVN and now I&#8217;m start thinking to migrate all the old projects to git. This because I like git very much and I use it personally for several years now. The first question but was: &#8220;Not invented here&#8221;-syndrom? Why not using github or codeplex or any other public platform which offers git support. Well, some of my&#8230;<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"https:\/\/blog.eweibel.net\/?p=1306\"> Read More<span class=\"screen-reader-text\">  Read More<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[7,14],"tags":[],"class_list":["post-1306","post","type-post","status-publish","format-standard","hentry","category-first-experiencies","category-software-engineering"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/plOV9-l4","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":954,"url":"https:\/\/blog.eweibel.net\/?p=954","url_meta":{"origin":1306,"position":0},"title":"Visualize changes in your repository","author":"Patrick","date":"17. Feb 2011","format":false,"excerpt":"As you perhaps know, there exists a very interesting project on Google code, with which you can visualize the activities on your repository: Gource. Getting started It supports Git, Mercurial, Bazaar and SVN. There is also a way to visualize the changes in a repository of a Microsoft Team Foundation\u2026","rel":"","context":"In &quot;New technology&quot;","block_context":{"text":"New technology","link":"https:\/\/blog.eweibel.net\/?cat=6"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":303,"url":"https:\/\/blog.eweibel.net\/?p=303","url_meta":{"origin":1306,"position":1},"title":"From NUnit to MSTest","author":"Patrick","date":"30. Jun 2009","format":false,"excerpt":"Last week I migrated several projects from NUnit to MSTest. The developers use the Developer version of Microsoft Visual Studio Team System, so they have integrated unit-test support for MSTest. In this post I show you all the problems and work I had to migrate the tests from NUnit to\u2026","rel":"","context":"In &quot;.NET&quot;","block_context":{"text":".NET","link":"https:\/\/blog.eweibel.net\/?cat=13"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":942,"url":"https:\/\/blog.eweibel.net\/?p=942","url_meta":{"origin":1306,"position":2},"title":"Enums and inheritance in .Net","author":"Patrick","date":"9. Feb 2011","format":false,"excerpt":"In one of my current projects I had the following code (I simplified the code a bit): public string ConnectionString { get { switch(this.Importer) { case Importer.SqlServer: return \"Server=localhost;Database=Northwind\"; case Importer.SqlServerOleDb: return\"Provider=SQLOLEDB;Data Source=localhost;Initial Catalog=Northwind\"; default: throw new NotSupportedException( string.Format(\"Importer {0} is not supported yet.\", this.Importer)); } } } After running\u2026","rel":"","context":"In &quot;.NET&quot;","block_context":{"text":".NET","link":"https:\/\/blog.eweibel.net\/?cat=13"},"img":{"alt_text":"CodeCoverage","src":"https:\/\/i0.wp.com\/blog.eweibel.net\/wp-content\/uploads\/CodeCoverage_thumb.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/blog.eweibel.net\/wp-content\/uploads\/CodeCoverage_thumb.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/blog.eweibel.net\/wp-content\/uploads\/CodeCoverage_thumb.png?resize=525%2C300 1.5x"},"classes":[]},{"id":1248,"url":"https:\/\/blog.eweibel.net\/?p=1248","url_meta":{"origin":1306,"position":3},"title":"VDD &#8211; the new programming manifesto?","author":"Patrick","date":"17. Jul 2012","format":false,"excerpt":"When I was at the NDC, I had also the possibility to visit with colleagues the city of Oslo. During a stop in front of a little shop, a colleague discovered a post card about Viking laws. When I read it, I was really surprised how well the laws fit\u2026","rel":"","context":"In &quot;Agile&quot;","block_context":{"text":"Agile","link":"https:\/\/blog.eweibel.net\/?cat=17"},"img":{"alt_text":"VikingLaws","src":"https:\/\/i0.wp.com\/blog.eweibel.net\/wp-content\/uploads\/VikingLaws_thumb1.jpg?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":1167,"url":"https:\/\/blog.eweibel.net\/?p=1167","url_meta":{"origin":1306,"position":4},"title":"Who should make decisions about technologies?","author":"Patrick","date":"13. Feb 2012","format":false,"excerpt":"One of the biggest problems of software engineering companies in Switzerland is currently to get new software developers. To get new employees there are several points as for example salary, environment, career possibilities and technologies. The last point looks easy but in reality it isn't that easy. Why are essential\u2026","rel":"","context":"In &quot;New technology&quot;","block_context":{"text":"New technology","link":"https:\/\/blog.eweibel.net\/?cat=6"},"img":{"alt_text":"Stay on course","src":"https:\/\/i0.wp.com\/blog.eweibel.net\/wp-content\/uploads\/Fotolia_36561464_S_thumb.jpg?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":622,"url":"https:\/\/blog.eweibel.net\/?p=622","url_meta":{"origin":1306,"position":5},"title":"Branching practices","author":"Patrick","date":"6. Apr 2010","format":false,"excerpt":"In an environment where several developers work at the same code base or several features have to be implemented, then branching will be a topic. I was asked to create a branching guide for my current employer which use TFS as source code repository. Motivation In our projects I found\u2026","rel":"","context":"In &quot;Good practices&quot;","block_context":{"text":"Good practices","link":"https:\/\/blog.eweibel.net\/?cat=5"},"img":{"alt_text":"image","src":"https:\/\/i0.wp.com\/blog.eweibel.net\/wp-content\/uploads\/image_thumb3.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/blog.eweibel.net\/wp-content\/uploads\/image_thumb3.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/blog.eweibel.net\/wp-content\/uploads\/image_thumb3.png?resize=525%2C300 1.5x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/blog.eweibel.net\/index.php?rest_route=\/wp\/v2\/posts\/1306","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.eweibel.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.eweibel.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.eweibel.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.eweibel.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1306"}],"version-history":[{"count":39,"href":"https:\/\/blog.eweibel.net\/index.php?rest_route=\/wp\/v2\/posts\/1306\/revisions"}],"predecessor-version":[{"id":1347,"href":"https:\/\/blog.eweibel.net\/index.php?rest_route=\/wp\/v2\/posts\/1306\/revisions\/1347"}],"wp:attachment":[{"href":"https:\/\/blog.eweibel.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1306"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.eweibel.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1306"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.eweibel.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1306"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}