Creating a Git Repository

From OCS Support Wiki

Jump to: navigation, search

Contents

Introduction to Git

Git is a source code management tool that focuses on speed and efficiency. It is different from many source code repositories in that each working copy is a full-fledged repository, and not tied necessarily to a central server. Updates to the repository can be pushed to other repositories, thus keeping them up to date. This allows for more decentralized management and easier branching and merging.

Creating a Git Repository for Your Website

This section will walk you through a practical application of using Git to manage your website files. You can apply these instructions to nearly any other use though.

To create a repository and work with it, you'll first need to (see Connecting via SSH).

In this example, you can change public_html to match that of your website folder (if you changed it), or your Rails app if you're running Rails:

cd ~/public_html
git init
echo "RedirectMatch 404 /\\.git(/|$)" >> ~/public_html/.htaccess

The last line puts a command in your .htaccess file (and creates that file if it doesn't exist) to tell the web server to ignore the .git folder and pretend like its not there for security reasons. This will prevent malicious activity and information about your repository being leaked to the public. It does not affect the functionality of your repository in any way.

Now that you have initialized a repository in your public_html, you'll need to add all of your files to it. To do this, run:

git add *

And we'll want to commit those changes to the repository:

git commit -a

You'll be prompted for a note about the changes. Just put "Initial import" and save the file for now, using the CTRL+X key if Nano is your default editor (if you don't know what this is, Nano will be your default editor and CTRL+X will save the file). Once done, this will commit the code.

This will be your basic workflow, add a file using git add * or git add filename.html (where filename.html is the name of your file to be added, or * adding all files), then committing with git commit -a.

To see what files have changed since your last commit, use the git status command.

Using Unfuddle

You can use Unfuddle to host your Git repository. The advantage to Unfuddle is that you get a complete ticket, documentation, and workflow system built around your repositories. You can also host Subversion repositories with Unfuddle. You can sign up for a free account easily if you did not elect to have OCS Solutions create one for you when you signed up with us. If you use the promotion code ocs your account will be flagged as having been referred by OCS Solutions, entitling you to exciting promotions and special offers in the future.

Inside the Unfuddle system help will be shown on creating a Git repository, or syncing your existing repository (as perhaps created from the above examples) with Unfuddle.

More Information

You can learn more about Git by visiting the official Git website.