Git part 1: Intro to git, setup a git server on CentOS and create a new project

What

From git-scm.com: “Git is distributed version control system focused on speed, effectivity and real-world usability on large projects.” It is the new subversion. Every coder seems to be using it and every coder seems be loving it. I’ve only scratched the surface with it and can already see how it will help me manage development on my current project.

In this article we’ll be setting up a private git server on a clean build of CentOS 6.2. If you don’t want to set up your own server, head on over to github and create an account (limited free and paid options).

Why

Say you have a new coding project you want to tackle. It’s going to be a long running, complex project and some of your friends might end up helping you with the code, so you want a way to easily collaborate with them without stepping on each others code as you work. A privately hosted git server is the perfect tool for this job.

Git helps a developer in several ways:

  • keeps track of the changes that are made to a project
  • can easily roll back changes to a known good state if you add some code that ends up not being the best idea
  • each developer in a project has their own local repository of all the code, which allows them to work on the same project simultaneously. The changes from each person are merged back together at the end
  • provides an easy, standardized mechanism to distribute code to users and allow them to update to the latest and greatest with only a few commands
  • provides several helpful tools to easily interact with source code revisions

How to get started

  1. Build yourself a server (VMs are great, especially for a lightweight application like git) and install the latest version of CentOS. I suggest adding a separate partition to use for your git projects and mount it in an easy to remember location such as /git, just to keep things clean and separate.
  2. Install git:
     [dan@git ~]$ sudo yum install git
  3. You’re done. Yup. That easy.

Now, how do you interact with it and create a project?

Setup a project

Let’s create our directory structure and a repository for our new project on the server:

ssh dan@git
[dan@git ~]$ cd /git
[dan@git git]$ mkdir awesome_new_project.git
[dan@git git]$ cd awesome_new_project.git/
[dan@git awesome_new_project.git]$ git init --bare # this command will
initialize the server side of your new repository and set up the
required git files and 'infrastructure.'
Initialized empty Git repository in /git/awesome_new_project.git/

One note – do not edit any files in the server directory directly other than ‘config’ or ‘description’. The other files are modified when you run various git commands and I will give a rundown of what these files are for in part three.

After this, you have a functioning git repository for your new project. You can develop code locally on multiple computers or collaborate on the project with others, and your code has a central place to live when you are done for the day. You don’t have any code in ysour repository yet, but stick with me and we’ll start using it! In part two we’ll begin interacting with our new repository as we write some code, and in part three we’ll cover branching, merging and conflict resolution.

References

stackoverflow: Why is Git better than Subversion?

2 thoughts on “Git part 1: Intro to git, setup a git server on CentOS and create a new project”

Leave a Reply

Your email address will not be published. Required fields are marked *