Setting up a Git Repo Server and interfacing to it with TortoiseGit

From K1VZX Wiki
Jump to: navigation, search

First question: What is Git? Git is a version control system. You check out files from a server and they are downloaded and synced to a workspace (folder and subfolders) on your local machine; this is in simple terms, of course. More complex setups use branches and even file stashes to maintain copies of code that differ from one another as new features are added or old code is refactored or made obsolete. Perhaps the biggest and most important feature is that of the push feature which tracks code as you add it to a repository. Pushing code requires a comment and careful selection of the files to be pushed, and is usually accompanied by an approval-signoff by a 3rd party who has reviewed the code.

This guide will be based on Debian 9, since that is the OS I currently run on my server. I imagine instructions for Debian 10 would be similar. I'll check that later.

Let's break this guide down into 2 parts: 1) Windows 2) Linux, and 3) back to Windows.

Just a note, I do have pictures to insert into this post, however I will get around to inserting them into this document at a later time.

Step 1: Installing TortoiseGit

  • Follow these steps on your Windows machine:
    • Before you run out and install TortoiseGit, search for Git for Windows. Download the installer for Git for Windows and install, just use all default settings with the exception of the default text editor. I prefer to use Notepad++ but you can choose whatever you want.
    • Now you can install TortoiseGit. As of the time of writing this article, the current version of TortoiseGit is and will only run on Windows 7 or above. The Git version installed by Git for Windows is 2.26.2. NOTE: There are other sources that you can acquire Git from, and they may or may not be compatible with TortoiseGit. CygWin is one source, or MinGW. When prompted for a path to Git, especially if you have other versions of Git installed, make sure that TortoiseGit detects the path to the instance of Git that you wish to use, and that it is the corrected, expected version.

Step 2: Setting up Git

For this step, we'll now be working on the linux machine. I assume you have a basic understanding of linux commands, editing configuration files, and working with the filesystem on your machine.

  • Make sure git is installed on your linux/unix/bsd/solaris/raspberrypi machine.
  • Make a folder somewhere on your machine that the user git can access (such as /var/git) and give it the proper permissions. The foldername must end in ".git" (without parenthesis) like below.
  • Change to the newly created directory and execute the following command:
git init --bare
  • If you do an ls -lsa inside the folder, you should see something like this:
git@ResKVM:~/project.git$ ls -lsa
total 40
4 drwxr-xr-x  7 git git 4096 Apr 15 00:46 .
4 drwxr-xr-x  6 git git 4096 Apr 20 05:13 ..
4 drwxr-xr-x  2 git git 4096 Apr 11 01:30 branches
4 -rw-r--r--  1 git git   66 Apr 11 01:30 config
4 -rw-r--r--  1 git git   73 Apr 11 01:30 description
4 -rw-r--r--  1 git git   23 Apr 11 01:30 HEAD
4 drwxr-xr-x  2 git git 4096 Apr 11 01:30 hooks
4 drwxr-xr-x  2 git git 4096 Apr 11 01:30 info
4 drwxr-xr-x 14 git git 4096 Apr 15 00:46 objects
4 drwxr-xr-x  4 git git 4096 Apr 11 01:30 refs

Step 3: Integrating the git repository with TortoiseGit

  • At this point, your git repository is setup. For the next part of this tutorial, I will assume that you already have SSHD installed on your linux host. When you installed TortoiseGit, an application was installed called Putty Gen. This is an alternative to a linux tool for generating public/private SSH keys. Basically, by setting up SSH keys, you will prevent having to enter a password everytime you interface to the Git repository. If this is something you would like, continue to the next step, otherwise you can stop here. Keys are specific to every individual machine they are generated from, and can be passphrase detected for an extra level of security.
  • Launch Pageant. Click 'Generate' and move your mouse cursor randomly throughout the empty box in the Putty Key Generator Window. If you would like to add a passphrase to your key, enter the passphrase now.
  • Select everything in the box above 'Key fingerprint' and copy it. Use your favorite terminal tool to SSH into the machine with the git repo and be sure to login as the user 'Git'. Edit the file ~/.ssh/authorized_keys file and past the entire line of text into this file. Save and close the file and editor.
  • Last, save the private key in a location where you will remember it, but others can't find it. This private key is necessary to negotiate the SSH connection between your system and the server.

Step 4: Configure TortoiseGit

  • At this point, you have all the tools and knowledge necessary. Create a repository on the server as per the instructions and make sure the folder name ends in .git. Initialize a bare repository.
cd /var/git/
mkdir /var/git/Test.git
cd Test.git
git init --bare
  • Now, create a folder on your development PC (or Windows PC, workstation, whatever you want to call it). Create a folder. Right click this folder and select 'Git Create repository here...' You will see a window that prompts you to select whether you want a bare repository or not. A bare repository is the repository that runs server side. It is empty by default: the only contents are the folders which store data about the master repository and all of its branches.
  • Next, if you right click the folder you just created the Git repository in, now you will see "Git Commit -> "master"... Comments about file changes go in the message field. The signed-off-by field allows a 3rd party to sign off on the changes before they get committed to say, a production code base. Changes made shows a glimpse of what changes have been made to your files. This works mainly for text files and not binary files such as LabVIEW VIs, however there are some tools to integrate Git based version control into LabVIEW (neither open source nor free however).
  • At the botttom of the window you will see a down arrow next to "Commit". Commit simply saves the state of your files/code to your local repo. You will need to do a push following the commit to synchronize the files with the git repository.
  • When you do a push, you will now have to edit some of the TortoiseGit settings mainly so that TortoiseGit knows where your repository is. Select "commit and push". The push window will open.
  • Select the remote field and enter:
ssh://git@<>/<location of repo>.git
  • Next, click the ellipses next to Putty Key and browse to the location of your *private* key. Click "Add New/Save". Click OK.
  • Next to remote, type in "master". Click OK.

You should see a success message. If not, check the owner and read/write permissions of the folders your Git repo is using.

That's the guide in a nutshell.