<p>I've decided to migrate this blog to <ahref="http://blog.getpelican.com/">Pelican</a>. I've been playing around with it over the week-end, and it turns out to be way easier to manage than <ahref="https://jekyllrb.com/">Jekyll</a>. Themes are much easier to install and configure, so it ends up looking better as well !</p>
<p>Since I'm basically recreating this blog from scratch, I've decided to delete the old git repo that was hosting it and to create a new one.</p>
<p>Setting up your own private git repo is pretty easy to achieve and is already well-documented on the <ahref="https://git-scm.com/book/en/v2/Git-on-the-Server-Setting-Up-the-Server">Git</a> website.</p>
<p>Every time I want to create a new repo, I've had time to forget how to do it and I end up looking for that page, so I figured I'd write a few lines on the subject.</p>
<p>In this tutorial, I'll configure a git repo on a distant server running Debian 8 (Jessie). This repo will be remotely accessible using SSH. Two users will be able to connect to it : me and the www-data user on my webserver.</p>
<p>For security reasons, configuring a passphrase is recommended. On Mac OS X and most desktop environnements on Linux, you can store this passphrase for the duration of your session using the <code>ssh-add</code> command, so you won't have to type it every time you want to connect to a host.</p>
<p>On the server, we also have to create a ssh-key for the user that is running our webserver (you'll need to have sudo installed) :</p>
<p>This will create a system user (UID < 1000) with a /home/git home directory. If you want to host your git repos somewhere else on your filesystem, you should add a <code>-d /home/directory/for/git</code> in the previous command.</p>
<p>This user will use the git-shell shell. This limits remote connection to that user to git commands (like the rssh shell can limit remote connection to a user to scp or rsync commands).</p>
<p>You can now copy/paste the content of the two <code>$HOME/.ssh/id_rsa.pub</code> files we've created earlier using the <code>ssh-keygen</code> command in <code>/home/git/.ssh/authorized_keys</code>.</p>
<p>The last thing we have to do is to create our first git repo. In this example, my project will be called 'captainarkdotnet' as it will be hosting this blog :</p>
<p>The files for my blog are store in the ~/Documents/projects/captainarkdotnet on my computer. Before doing anything else, we first have to make sure that we currently are in that folder :</p>
<p>Please note that you'll need to edit <strong>git.captainark.net</strong> to the FQDN or IP of your git server, and <strong>captainarkdotnet.git</strong> to the name of the git project on your server.</p>
<p>If everything went well, the last command should give you the following output :</p>
<p>That's it, we've now pushed our first commit to our server !</p>
<h2>First pull</h2>
<p>Alright, time to pull the files we've just pushed on our webserver. I personally store my web content in <code>/var/www</code> ; if you don't, you'll have to adjust the path accordingly :</p>
<p>SSH will ask you to type 'yes' since it's the first time the www-data user connects to the server. If everything goes well, you should have the following output :</p>
<divclass="highlight"><pre>Cloning into <spanclass="s1">'captainarkdotnet'</span>...
<p>That's it ! We now have a working private git repo ! I won't go into details into the git commands in this tutorial, but here's a quick overwiew of the ones I use the most :</p>
<ul>
<li><code>git add .</code> recursively adds all files from the directory to the repo ;</li>
<li><code>git commit -a -m 'This is a comment'</code> commits the current state of your local repo with the 'This is a comment' comment ;</li>
<li><code>git push</code> pushes your commits to the distant repo ;</li>
<li><code>git pull</code> pulls the latest version of the distant repo locally ;</li>
<li><code>git branch -av</code> shows all available branches for the repo ;</li>
<li><code>git checkout -b testing remotes/origin/testing</code> create a local 'testing' branch based on the remote 'remotes/origin/testing' branch ;</li>
<li>once a branch has been copied locally, you can switch to it with the <code>git checkout {branch}</code> command.</li>
</ul>
<p>For more information on git a command, use <code>man git-{command}</code> !</p>
<p>If you've found this tutorial in any way helpful, please feel free to leave a comment !</p>