Category Archives: Git

Setup git-http-backend on ubuntu / apache

Description

GIT

GIT

Since version 1.6.6 GIT is able to tunnel its native protocol through HTTP or HTTPS. In this post I describe how to set things up so you can use GIT over HTTP(s). As always it is best to make use of HTTPS for security reasons. In this setup we use Basic authentication so you better use HTTP

I also use virtualmin to keep my hosting business running but that should not be a problem when following along with the steps in this post.

Preparation

Ok first of all create a subdirectory in your public_html  (document root) directory. This is where we are going to store the repositories. I suggest you call this directory….git (lowercase). Change directory to your new folder.

Apache htaccess and htpasswd

We are going to create a couple of CGI scripts to have more control over the way the backend is executed. First create a .htaccess file with the following contents:

This tells apache that it is ok to execute a CGI script from this folder (line 1, 2). It also tells apache to require a “valid-user”; this user can be found in the .htpasswd file (see below). Now we have to create a password file for the user authentication:

For testing purpose you could create an index.html  file and try to open that in the browser. The browser should ask your username and password now.

CGI Scripts

Now create a CGI script that will initialise a new bare repository for us to use. Create an init.cgi  script with the following contents (extend parameter checking if you wish).

init.cgi

When you execute this script via the browser ( https://yourdomain/git/init.cgi?reponame=[yourreponame] ) a new bare repository is created. The actual repositories are created in the subdirectory repos below the git folder.

The next script will startup the actual GIT http backend. I have wrapped this in an additional script so I could perform some logging. Create a script called git.cgi  in your git directory with the following contents.

git.cgi

Finally you need a little configuration script, named config.sh , which sets some general parameters. Source is shown below.

config.sh

Now you can clone a repository by sending your browser to the url

Example workflow

In your browser: https://[yourdomain]/git/init.cgi?reponame=first
In your shell (local): git clone https://[yourdomain]/git/git.cgi/git/repos/first.git
Apply your changes
Add all items to the staging area: git add --all
Commit all changes in the staging area: git commit -am "My commit message"
Push the changes back to the server: git push

That’s all; happy GITing

Share

Windows GIT and SSH keys

gitTo use SSH keys on your windows system follow the steps below:
Install the git extensions for windows. This will (among other things) install the Git Bash shell. Execute a git bash shell. Now create your private/public key pair with the ssh-keygen command (or copy an existing key). Add a passphrase for additonal security.

On windows the ssh files are store in c:\Users\Administrator\.ssh\

Copy the public part to your git server with the ssh-copy-id command.

In Git bash edit your .profile (or create one) and add the coding snippet below:

If you have multiple keys you should also create a config file in the .ssh folder. In this file you specifiy which key should be used for what host; like this:

Share

Setup GIT server

This post describes how to setup your ubuntu server as a GIT server. Clients are able to clone repositories and push their changes back to the server with this setup. We make use of ssh in combination with the git-shell to provide extra security.git

On your GIT server execute the commands below:

If you use a Synology server add the following line to your /etc/shell file:
/var/packages/Git/target/bin/git-shell

Create a bare GIT repository on the server at /opt/git:

Now on your local machine create a repository  and push it to the server:

To clone the repository to your local development machine execute the following commands:

When you have made changes to a file you want to undo (revert changes back to the last commit) execute the command below:

GIT and SSH public / private key

If you want to use git with a SSH key follow these steps. A SSH key is a convenient (and very secure!) way to login to your server. First create a public / private key pair with the command (-t is the type of encryption and -C is a comment):

Protect this key with a strong passphrase. After the key is generated you have to copy the public part to the server. Off course this should also be done in a secure way so use the ssh-copy-id tool for this. Execute the command:

The ssh_agent will ask for your passphrase (not the user password) and remember it. If you don’t have a ssh_agent enabled you could do without the passphrase but that is a bit less secure.

Share

Working with Visual Studio 2010 and github on Synology

gitInstall the  "GIT server"  package on your Synology Disk Station. Goto the package center and search for the “Git Server” package. Download and install it.

Install GitExtensions on your dev box.

Install the latest msysgit on your dev box.

Install the  "Git Source Control Provider"  Visual Studio 2010 extension on your dev box. In Visual Studio goto Tools -> Extensions and search for “Git Source Control Provider” in the online gallery.

Now SSH to your Synology (either with putty or with a Linux terminal) and execute the following commands:

This will create a so called “bare git” repository. A bare git repository can be used as a central repository to which you push your local repositories.

Ok; now there is a GIT repository created on your Synology. Next create a new Visual Studio solution. Right click the solution name and select “Create Git Repository”. This will add an .git folder to your solution directory and now your solution is in a local Git repository.

Next commit your new solution to the Git repository.Select all files; type your comment and hit “Commit”.

Now push your local repository to the central bare git repository you created earlier. Right click the solution name; choose Git (master) -> Push. The checklist for Git settings will show up if not all settings are valid. For now just click Ok. The Push dialog appears. Specify the remote name; for example: ssh://johndoe@10.0.0.1/volume1/repo1.git

Some useful GIT commands
In Visual Studio goto GIT -> GIT bash; a Bash command prompt will start.
Show available tags:

Create a tag in the GIT bash:

Commit your changes with a message:

Push the tag information:

Delete a tag:

GIT Use Case

Create bare repo on diskstation

On a client clone (initialise) a repository from the dskstation:

[Remote “origin”] can be found in .git/config file; you could add an alias for convenience. A directory repo will be created that contains your files. Add files to your repo directory

Add them to the local stage:

Commit them to the local repo:

Push them to the server repo:

A new branch master will be created. From now on you can use git push (without the origin master)

Share