Third party cookies may be stored when visiting this site. Please see the cookie information.

Git - Version Control that's addictive

Git is a version control system. A way of keeping regular backups of files which is particularly useful for creating computer source code.

I've used other version control systems before (CVS and Subversion) and other tools that provide an element of version control (eg. Dropbox), but so far I've only really used them when I needed to for specific software projects. Elsewhere I've been manually creating backups as required, which includes the code and data files used in my websites. I first starting using git almost 2 years ago and continued to use it in the same way as I did before. I've since learned more about Git and my use of version control has now completely changed.

GitHub profile - Stewart Watkiss / PenguinTutor

I had picked up the basics of git through some projects I've been working on and I started using it for my own projects, but just by having an account on github and pushing my open source project code there. I had read up on how to use git, but was just using it in a similar way to how I used the other version control systems before. I am now studying for an MSc in Computer Science with Georgia Tech and my current class on Software Development Process (CS 6300) includes git as one of the "tools of the trade".

As well as the course video I have watched a Udacity course. Note that Udacity also provide the platform for my degree course which is where I found this course.

Udacity course - How to Use Git and GitHub

Simple personal git repository

GitHub is the main provider of git repositories and is free for open source projects. It does support private repositories, but there is a charge for this. The cost is reasonable and it provides the reassurance of a professional run server but I just wanted something that I could run on my own server. It is possible to install a full blown git server using GitLab, but for a basic repository it's possible to create a basic server just using ssh - which I already had installed.

I created a git user with login restricted to git shell (/usr/bin/git-shell) and copied my public key for my other computers to /home/git/.ssh/authorized_keys

I then created directories for each of the repositories and initialized them as git repositories using

git init --bare

and I could then push and pull to the repository.

Note that as I'd disabled login as git I switched to the git user using

sudo -su git

I've used this for maintaining the files used for my websites.

Customization

These are some of the customizations I have done.

git config --global user.name "User Name"

git config --global user.email name@example.com

git config --global core.editor "vim"

git config --global push.default upstream

git config --global merge.conflictstyle diff3

git config --global color.ui true

Download completion

wget https://github.com/git/git/raw/master/contrib/completion/git-completion.bash

wget https://github.com/git/git/raw/master/contrib/completion/git-prompt.sh

In .bashrc

I added the entries

source ~/git-completion.bash

green="\[\033[0;32m\]"

blue="\[\033[0;34m\]"

purple="\[\033[0;35m\]"

reset="\[\033[0m\]"

source ~/git-prompt.sh

export GIT_PS1_SHOWDIRTYSTATE=1

export PS1="$purple\u$green\$(__git_ps1)$blue \W $ $reset"

More information

There is lots more information available on Git. Here are a few I've found useful.


» PenguinTutor Facebook page