Tuesday, January 24, 2012

Manage Local Projects with a Git Repository

Most people working on small projects will not need a form of version control. However, as the scope of a project grows, it may be time to better manage the milestones of the project. A major benefit of using a local version control tool is the ability to revert to prior versions of a project if necessary. It also works as a backup, though will not supplant any type of backup run on the local system.

There are many different version control tools out there, but for this example I chose to use Git because of its popularity in the open source community. You can read more about Git here: http://git-scm.com/.

Download and Install Git

Depending on the system, installation instructions will vary. In Ubuntu, you can simply type the following:

sudo apt-get install git

For other installations, go here: http://git-scm.com/download.

Start a Local Git Repo

To start a new repository, navigate to the desired directory and create a folder with the .git extension:

cd ~/gits/
mkdir project.git

Now change into the new directory and initialize a bare Git repo:

cd project.git
git init --bare

And just like that, the repo is ready to handle revisions!

Create a Clone for the Project

With the new Git repo ready to go, now is a good time to do an initial commit for the project. Navigate to the desired working directory of the project and clone:

cd ~/workspace/
git clone ~/gits/project.git project

There will be a new directory project in the working directory. This is where any files for the project should be created/removed/modified.

Do an Initial Commit

Add a new file to the project! As an example, lets create some new Python scripts:

cd project
touch this.py is.py cool.py

Now, add the files to the repo (specifying each file one by one is also an option):

git add *

Finally, commit the changes:

git commit -m "Initial commit for the project."

The project has now created a new revision based on the commit!

A good cheat sheet for Git can be found here: http://help.github.com/.

Ramblings of the Sleepy: http://tiredblogger.wordpress.com/2009/11/09/creating-local-git-repositories-yeah-its-that-simple/
Git Cheat Sheet: http://help.github.com/git-cheat-sheets/

No comments:

Post a Comment