Git in Web Development

From Metro Studios Knowledgebase

Jump to: navigation, search

Contents

[edit] Abstract

Using Git in web development requires a specific setup of Git that is unique to many coding situations. Because we are not testing our sites on our local machines (as a normal programmer would compile/test code on his own workstation) we have configure Git to publish our files to the public web directory we need them in.

[edit] Bare Repositories

In order to create a web development specific setup in Git we have to use what's called a bare repository. The biggest difference between a normal repository and a bare repository is that the bare repository does not have a worktree established. We take advantage of this in the three repository setup the most where you would push directly onto a bare repository. Alternatively this allows us to be able to push from our live httpdocs repository/directory back onto the bare development repository.

The second difference of a bare repository is that it actually has a name rather than just being a ".git" directory. In the current setup we are using a "repo.git" as a generic name, and we're hosting them within the base vhost directory, ex: "/var/www/vhosts/example.com/repo.git/".

[edit] Hooks

We will also need to take advantage of the built in scripting that Git offers. In any Git repository there is a "hooks" directory. This contains shell scripts that run on certain events when handling repositories. The list of events is as follows:

[edit] Two Repository Setup (only production site)

ex: local repository (on workstation) -> live repository (on server) -> live httpdocs directory (on server)

[edit] Initializing the Git Repository

Create a Git repository using the git init command from within the site/application's document root.

cd /var/www/vhosts/sample.com/httpdocs/

git init

If there are any existing files within the site's document root (from a site/application) then we must add them to the repository and run an initial commit so that they are tracked in the repository we just created:

git add .

git commit

[edit] Three Repository Setup (with development site and production site)

ex: local repository (on workstation) -> development bare repository (on server) -> development httpdocs repository (on server) -> live httpdocs repository (on server)

Personal tools
Namespaces
Variants
Actions
Wiki Navigation
Knowledgebase
Toolbox