{"id":2487,"date":"2024-12-16T06:25:22","date_gmt":"2024-12-16T06:25:22","guid":{"rendered":"https:\/\/cdblog.cdstealer.com\/?p=2487"},"modified":"2025-03-07T15:46:13","modified_gmt":"2025-03-07T15:46:13","slug":"gitweb","status":"publish","type":"post","link":"https:\/\/cdblog.cdstealer.com\/?p=2487","title":{"rendered":"GitWeb"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>Emerge git with the required USE flags:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>emerge -aq dev-vcs\/git curl gpg iconv nls pcre perl safe-directory webdav cgi cvs highlight keyring tk<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Configure Apache vhosts (NO AUTH):<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;VirtualHost *:443&gt;\n\t  SSLEngine on\n        &lt;FilesMatch \"\\.(cgi|shtml|phtml|php)$\"&gt;\n          SSLOptions +StdEnvVars\n        &lt;\/FilesMatch&gt;\n        &lt;Directory \"\/var\/www\/localhost\/cgi-bin\"&gt;\n          SSLOptions +StdEnvVars\n        &lt;\/Directory&gt;\n          SSLCertificateFile \/path\/to\/cert.crt\n          SSLCertificateKeyFile \/path\/to\/key.key\n          ServerName git.example.com\n          DocumentRoot \/usr\/share\/gitweb\n\t  Options ExecCGI FollowSymLinks SymLinksIfOwnerMatch\n\t&lt;Location \/&gt;\n\t  SSLRequireSSL\n<em>\t  <mark style=\"background-color:#24890d\" class=\"has-inline-color\">Require all allowed\n<\/mark>          <mark style=\"background-color:#24890d\" class=\"has-inline-color\">RewriteOptions inherit\n<\/mark>          <mark style=\"background-color:#24890d\" class=\"has-inline-color\">AllowOverride All<\/mark><\/em>\n\t&lt;\/Location&gt;\n        &lt;Directory \/usr\/share\/gitweb&gt;\n          Require all granted\n          RewriteOptions inherit\n          AllowOverride All\n          Options ExecCGI FollowSymLinks SymLinksIfOwnerMatch\n          &lt;Files gitweb.cgi&gt;\n            SetHandler cgi-script\n          &lt;\/Files&gt;\n        &lt;\/Directory&gt;\n\t  DirectoryIndex gitweb.cgi\n          SetEnv  GITWEB_CONFIG  \/etc\/gitweb.conf\n        &lt;IfModule headers_module&gt;\n          RequestHeader set X-HTTPS 1\n        &lt;\/IfModule&gt;\n&lt;\/VirtualHost&gt;\n\n<strong>Basic \/etc\/gitweb.conf<\/strong><\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>$projectroot = '\/path\/to\/gitroot';\n@git_base_url_list = ( 'git@example.com', );\n$site_name = \"Smack my git up!\";\n$default_projects_order = \"age\";\n$projects_list_group_categories = 1;\n$feature{'blame'}{'default'} = &#91;1];\n$feature{'highlight'}{'default'} = &#91;1];<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Adjust git-daemon<\/strong><br>Gitweb allows browsing repositories via HTTP, but if you will be pulling from your repositories using the git:\/\/ protocol, you'll also want to run git-daemon. On Gentoo, this is really easy, just edit \/etc\/conf.d\/git-daemon as you see fit. eg:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">GITDAEMON_OPTS=\"--syslog --enable=receive-pack --export-all\"<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This exports all repositories within the git root. It also allows pushing file to the server.<br><br>You will also need to ensure that any clients to connect to port tcp\/9418 (default)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Setup the git user<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">useradd -m git -d \/path\/to\/githome -s \/usr\/bin\/git-shell<br>mkdir \/path\/to\/githome\/.ssh<br>cat \/home\/A_USER\/.ssh\/id_rsa.pub &gt; \/path\/to\/githome\/.ssh\/authorized_keys<br>chmod 700 \/path\/to\/githome\/.ssh<br>chmod 600 \/path\/to\/githome\/.ssh\/authorized_keys<br>setfacl -PRdm u:apache:rwx \/path\/to\/githome<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Create an Empty Repository<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">su -s \/bin\/bash git<br>cd<br>mkdir name.git<br>cd name.git<br>git init --bare<br>echo \"This is a test\" &gt; description<br>git remote add origin git@example.com:name.git<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Set Configuration Options<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Execute the following on a client (optional)<br>To see available options execute: git help --config<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">git config --global init.defaultBranch master<br>git config --global core.editor vim<br>git config --global alias.st status<br>git config --global alias.co checkout<br>git config --global alias.br branch<br>git config --global alias.up rebase<br>git config --global alias.ci commit<br>git config --global user.name \"A_USER\"<br>git config --global user.email A_USER@example.com<br>git config --global color.ui true<br>git config --global --add --bool push.autoSetupRemote true<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Clone Repo<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">cd to local git<br>git clone git@example.com:name.git<br>cd name<br>touch README.md<br>git add README.md<br>git ci -m \"Initial Setup\"<br>git push<br>git br branch_name<br>git co branch_name<br>mkdir testdir<br>touch testdir\/testfile<br>git add .<br>git ci -m \"init\"<br>git push # Pushes to your upstream branch<br>git push origin branch_name:master # Pushes to the master branch<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Web Authentication<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Note:  I did not have any success using dbmmanage.  Use htdbm instead.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Create the database file and add a user:<br>Do not store this in the root of web eg: \/var\/www\/locahost\/htdocs, but make sure apache can get to the file.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">htdbm -cm -TGDBM &lt;path\/to\/dbm_file&gt; &lt;user&gt;<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">-c - create db<br>-m - use MD5 hashing<br>-T - set the format of the db file<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Set the permission for apache:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">chown apache: &lt;path\/to\/dbm_file&gt;<br>chmod 640 &lt;path\/to\/dbm_file&gt;<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Add code to vhosts:<br>You can apply this to files, directories etc. Here I've done it for the whole subdomain. Replace the 3 highlighted italic lines above with the code below, excluding the start\/end tags.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    &lt;Location \/&gt;\n      AuthName \"Private\"\n      AuthType Basic\n      AuthBasicProvider dbm\n      AuthDBMType GDBM\n      AuthDBMUserFile \"\/path\/to\/dbm_file\"\n      Require valid-user \n      Require all denied\n      RewriteOptions inherit\n      AllowOverride All\n    &lt;\/Location&gt;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Reload apache and browse to protected area and you should be prompted to authenticate.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"320\" height=\"258\" src=\"https:\/\/cdblog.cdstealer.com\/wp-content\/uploads\/Screenshot-from-2025-01-19-12-29-33.png\" alt=\"\" class=\"wp-image-2523\" srcset=\"https:\/\/cdblog.cdstealer.com\/wp-content\/uploads\/Screenshot-from-2025-01-19-12-29-33.png 320w, https:\/\/cdblog.cdstealer.com\/wp-content\/uploads\/Screenshot-from-2025-01-19-12-29-33-300x242.png 300w, https:\/\/cdblog.cdstealer.com\/wp-content\/uploads\/Screenshot-from-2025-01-19-12-29-33-150x121.png 150w\" sizes=\"auto, (max-width: 320px) 100vw, 320px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">A good explanation can be found <a href=\"https:\/\/howtolamp.com\/lamp\/httpd\/2.4\/securing\/auth-basic-dbm\/\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a> for the web config.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Emerge git with the required USE flags: Configure Apache vhosts (NO AUTH): Adjust git-daemonGitweb allows browsing repositories via HTTP, but if you will be pulling from your repositories using the git:\/\/ protocol, you'll also want to run git-daemon. On Gentoo, this is really easy, just edit \/etc\/conf.d\/git-daemon as you see fit. eg: GITDAEMON_OPTS=\"--syslog --enable=receive-pack --export-all\" &hellip; <a href=\"https:\/\/cdblog.cdstealer.com\/?p=2487\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">GitWeb<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[45,213,106,18],"class_list":["post-2487","post","type-post","status-publish","format-standard","hentry","category-gentoo","tag-apache","tag-gentoo","tag-git","tag-linux"],"_links":{"self":[{"href":"https:\/\/cdblog.cdstealer.com\/index.php?rest_route=\/wp\/v2\/posts\/2487","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cdblog.cdstealer.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cdblog.cdstealer.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cdblog.cdstealer.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cdblog.cdstealer.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2487"}],"version-history":[{"count":22,"href":"https:\/\/cdblog.cdstealer.com\/index.php?rest_route=\/wp\/v2\/posts\/2487\/revisions"}],"predecessor-version":[{"id":2547,"href":"https:\/\/cdblog.cdstealer.com\/index.php?rest_route=\/wp\/v2\/posts\/2487\/revisions\/2547"}],"wp:attachment":[{"href":"https:\/\/cdblog.cdstealer.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2487"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cdblog.cdstealer.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2487"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cdblog.cdstealer.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2487"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}