Setting up git on a server

From All n One's bxp software Wixi

Jump to: navigation, search

1 Overview

git is a version control management tool that is very cool but is a bit difficult to get set up and scary as it uses dos commands. The benefits really outweigh the cons. Firstly we need a server to do all this so... this doc outlines how to set up a server for a Windows environment for a team to work on a SaaS solution.


So lets get started


2 Setup

2.1 The Infrastructure

Ok, we start with a server, which allows all the team members pop things into centrally.


This server gets IIS installed, which means you're going to have a c:\inetpub\wwwroot folder or something very similar (maybe even an Apache folder).


Ok, into that we put our project. It should all be working lovely as a web server.


2.2 Get git going

Easily done and installed with all the default options.


https://git-scm.com/downloads


Now we have git on the machine and we have the ability to right click on our wwwroot folder and choose "git bash" from within Windows.


Make sure you're in the wwwroot directory


You'll then need the following commands

git config --global user.name 'Administrator'
git config --global user.email administrator@allnone.ie


Next we need to start the repository

git init 
git add .
git commit -m "Initial Repository"


Now we have a git repository set up and ready to share.


Now... we are a developer on the server emoticon with all the files in there... so we make the server go off on a separate branch to reduce error messages about Administrator working on the master branch.


git checkout -b OriginBranch


Your server is now ready to rumble.


2.3 Allowing Remote

Now we need to allow ssh connections with the server. This requires BitVise WinSSHD server which is really cool software. Install that bad boy and get the service started.


You can use the service on a different port, so work away if you need to. We set ours to something ... e.g. 9999


Now, we need to create some users. We're going to use Virtual Accounts, so we don't need to worry about AD integration for the moment.


Add the virtual account. Now you need to set the user up to use bash.


gitserver 001.png


So you should now make sure that the Virtual Group is also configured, through Edit Advanced Settings.


gitserver 002.png


So now you should be able to connect to your server from a remote machine.

2.4 Remote machine

So we have a remote repository. We have an SSH server to allow connections to it. Now your remote machine can pull down your repository.


Install git on your local machine the same as your server.


Go to your local inetpub folder (not the wwwroot). Right click on the background and choose "git bash".


Now you set up your machine.

git config --global user.name 'Your Name'
git config --global user.email your.name@allnone.ie


and if you like using Notepad++

git config core.editor "'C:\Program Files (x86)\Notepad++\notepad++.exe' -multiInst -notabbar -nosession -noPlugin"


Now we can get the repository onto our machine.

git clone ssh://your.name@serverip:port/c/inetpub/wwwroot


Your repository should now build into your wwwroot and you can test it locally.


Hey presto, you're up and kicking.


2.5 Checking it is working

So now you have files downloaded... right click on the white of wwwroot and choose "git bash"


2.5.1 Create a branch

git checkout -b Demo1

add a file somewhere in wwwroot... go on hide it!

git status

You should see your file in the list

git add .
git commit -m "Demo1"


2.5.2 Merge back into master

git checkout master
git merge Demo1

we check for updates

git fetch
git merge
git commit -m "Demo1a"

we put it back into the master

git push

2.5.3 Remote machine update

Now all the data is actually on the server, but it isn't live yet...

Here is a handy batch file

@echo off
cd \
cd inetpub
cd wwwroot
git checkout OriginBranch
git merge master
PAUSE