I have recently installed and used Git for the first time and I have been impressed by its excellent modular and distributed design, speed, efficiency and usefulness. So what is Git?
Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency. It may be used as a source control management system by software developers. However, it has a much wider remit and may be used as a version control system for all documents, spreadsheets, presentations and so on.
For some people approaching Git for the first time, it may appear somewhat daunting and overwhelming – not sure where to start, and then how to proceed once on the journey. Thus, the purpose of this article is to provide concise tips and references to facilitate you to get up and running quickly with Git.
Benefits of Version Control
Before jumping into the technical details, I want to briefly outline some of the benefits of a Version Control System (VCS). They include:
- Providing snapshots of your documents and the ability to easily go back to an earlier version/revision of your work.
- Facilitating an efficient and well managed organisation of documents. Experienced document authors compensate for not having a document management system by developing their own naming conventions for each document revision. As a result, their Documents folder is littered with many revisions of documents using specialized file naming conventions such as file name – date – revision.ext. A version control system replaces this chaos with a well structured consistent, reliable, efficient and easily managed organisational structure that allows you to focus on the work at hand – the content of your documents.
- Provides accountability – the ability to maintain and search what was edited when and by whom and what they did. This is of particular importance when working in a team or collaborating with external members.
- Adapting to use whatever workflow is appropriate for your project – centralised, distributed, Gatekeeper, and so on.
- A real time-line of effort put in to complete a project – helps in estimating new projects and billing complete ones.
- Provision of a backup service (if using a remotely hosted source control solution).
- Parking projects and then taking them up months/years later and jumping right in by reviewing your comments on what you already did up to the point where you left off.
- Take risks and make changes knowing that you can always restore a project to a point in time.
- The ability to create new “branch” versions. This feature can be useful for making bug fixes when projects have already been released to the field and the next build of the project is in development.
- Branching also facilitates parallel development. If several people are working on the same project, an integration branch can be created. When any party has new working code, it can be merged to the integration branch where all parties can use the change.
- Conserving disk space – The VCS only stores the latest version of a file and the differences between each version that precedes it. Thus the disk space required is usually several orders of magnitudes smaller than what would be required with a VCS.
Install Git and Get up and Running Quickly
- If you are new to version control, it is highly recommended you familiarize yourself with the concepts. An excellent visual introductory guide to version control is available online.
- To Install Git on Windows:
- There are several different Git installation packages available for installation on Windows.
I recommend you download and install GitExtensions (which includes MSysGit and KDiff3). It has the following features:- Windows Explorer integration for Git.
- Visual Studio (2005,2008,2010) plugin for Git.
- Can be integrated with the Eclipse IDE.
- Feature rich user interface for Git.
- Single installer installs Git (MSysGit), GitExtensions, Putty and the merge tool KDiff3.
- 32bit and 64bit support.
- A step-by-step screenshot analysis of each stage of the installation process is available. In essence, accept the default settings at each stage.
- Note: I suggest one change to the default settings:
When prompted to Adjust your path environment during the Git installation, I recommend selecting:
Run Git from the Windows Command Prompt
This will simply allow you to run Git from the command prompt regardless of your current working folder.
- There are several different Git installation packages available for installation on Windows.
- To install Git on Ubuntu Linux:
- The version installed by apt-get is quite old. There are simple instructions available to install the latest current stable version here. I recommend installing git-core, git-doc, gitk and git-gui.
- To Create a New Repository using the graphical user interface:
- Run Git Gui.
- Create a new Repository and choose a project folder.
- Select everything under Unstaged Changes.
- From the MenuBar, Select Commit | Stage to Commit
- In the box on the bottom-right of Git Gui, labeled Initial Commit Message, Enter the commit message.
- The message may include such details as:
Title_of_Commit
Name_of_commiter: Joe Bloggs
Date: 01-01-2000
Version: 00.01.00
Description of Changed made: Several line description.
- The message may include such details as:
- Select the commit button beside bottom window.
- To Create a New Repository using the command line:
It is even easier to create a new repository from the command line.- Open up a command prompt (windows) or terminal (Linux) and change directory to the project folder. Then enter the following commands:
- To create the new repository:
git init - To add all the contents of the folder into the Git repository:
git add . - Finally, to commit the files to the repository:
git commit -m “InitialisedRepository”
- To create the new repository:
- Open up a command prompt (windows) or terminal (Linux) and change directory to the project folder. Then enter the following commands:
- To Configure the Eclipse IDE to use Git Gui as an embedded version control management tool:
There are two excellent and short video tutorials on Youtube to demonstrate this.- Using Git GUI with Eclipse Part I – Setting up the workspace
- Using Git GUI with Eclipse Part II – Pushing changes to the server
Indeed, the method outlined in the videos may be used to integrate Git Gui with any software application that supports external tool configuration and invocation.
Online Resources to help you on your way
- Some excellent online resources for learning and using Git:
- The Official Online GIT Book – Complete Version. – This is a very good starting resource.
- ProGit – An excellent resource for someone new to Git.
- Quickstart Tutorial to Using Git.
- Everyday Git with 20 Commands or so.
- Understanding Git – A Conceptually Approach
This tutorial primarily explains the Git universe and its objectives, and secondarily illustrates how to use Git commands to manipulate that universe. - Aha! Moments When Learning Git
- Git for those who come from an SVN background.
- Executive Summary of Git commands when you already know the basics.
- Nice Git CheatSheet.
- Git for the Lazy.
- Branching and Merging Explained.
- A Concise Introduction to Git for Linux Kernel Hackers.
- GitReady – Learning Git one commit at a time.
- The Official Git FAQ.
- A Visual Git Reference
- The Official Git User Manual (rather terse).
- A Comprehensive list of tools that may be used with GIT.
- A Comprehensive list of Git Documentation on the Internet.
- Some excellent video screencasts explaining how to use Git:
- GitCasts – Online screencasts explaining how to use Git
- Getting started with GitHub – Free Online Git Hosting Repository.
Git Tips
- To configure Git to use an Internet Proxy:
If your computer passes through a Proxy in order to access the Internet, then Git must be configured to use this Proxy when interacting with repositories on the Internet. The command to enable Git to use a Proxy is:
git config –global http.proxy http://our-proxy-server:8088 - To configure Git to ignore certain file types:
Git may be configured to ignore certain filetypes by placing entries in the GIT_DIR/info/exclude file located in the project folder.
Note: This file must be ready before any files are committed to the Git repository (i.e.: immediately after git init).- The entries may be as follows:
*.aux
*.log
*.blg
*.[oa]
filename.ext
- For more information, refer to the relevant chapter in the online Git Community Book.
- The entries may be as follows:
- To checkout just one or two files from an older version to be included in the current version:
Occasionally it may be necessary to check out an old version of just one file and include it in the current working branch (as opposed to checking out the entire older branch just to get that one particular file) The instructions are in the Git User manual. - To setup your own Git Host Repository:
There is an excellent guide online explaining step-by-step how to setup a (simple) new remote online repository.
The steps detailing how to setup a more advanced GIT host repository with automatic user management on a Ubuntu server with clients connecting from Windows are available here.
To access (push, pull and fetch) a GitHub repository from behind a proxy.
The original reference for these instruction are available here.
The typical scenario behind a proxy is:
- All internet access passes through a proxy.
- The proxy allows outward connections of type HTTP and HTTPS only (ports 80 and 443 respectively).
- The CONNECT method is only enabled for port 443.
- Optionally, proxy authentication is required.
Windows Platform
- Install GitExtensions (as described earlier).
- Generate your SSH key if you have not already done so and add it to your GitHub account (instructions are available online). It is also highly recommended you generate a passphrase from reasons outlined here.
Note: Using Git Gui you may generate your SSH key and passphrase very easily from the menu bar by selecting Help | Show SSH Key | Generate Key. - Download the utility connect which permits the tunneling of various network connectinos via HTTP(S) proxies.
The source code connect.c is available for download and compilation. A pre-compiled binary for windows users is available.
I placed connect.exe in C:\software\connect\connect.exe - Backup your existing SSH config file (if it exists).
- Create a new SSH config file called config-proxy and place the following text in that file.
(Note: the text from ProxyCommand to %p should be on one line with a space after “-H”).ProxyCommand C:/software/connect/connect.exe -H proxy.site.com:443 %h %p
Host github.com
User git
Port 22
Hostname github.com
IdentityFile “C:\Users\username\.ssh\id.rsa”
TCPKeepAlive yes
IdentitiesOnly yesHost ssh.github.com
User git
Port 443
Hostname ssh.github.com
IdentityFile “C:\Users\username\.ssh\id.rsa”
TCPKeepAlive yes
IdentitiesOnly yes - Finally, when connecting to your Github repository, specify the remote location as follows (replacing the uppercase words to the appropriate values corresponding to your details):
ssh://git@ssh.github.com:443/USERNAME/PROJECTNAME.git
For example, to clone an existing project:
git clone ssh://git@ssh.github.com:443/USERNAME/PROJECTNAME.git - That’s it!
Google Tech Talks
- What is Git – A talk by Randal Schwartz. He presents a good technical overview of Git.
- Linus Torvalds, the creator of Git, visited Google to share his thoughts on the source control management system. This high-level talk highlights the differences between Git and the alternative version control systems and is quite entertaining as Linus as some strong views on technical matters and design philosophies