I have an old PHP website that I wanted to have its code/content versioned with Git, normally Git setup the repo directory in the “.git” directory inside the working directory, but I faced a problem, if the working directory is accessible from the web server it means “.git” is also accessible too.
Luckily git have an option to have the repo directory located somewhere else using the GIT_DIR environment variable, so here what I did:
$ vi .profile
You notice that the web site is located in “/var/www/my_website” but the repo is located under totally different directory “/home/rayed/my_website_git”, so the web server can’t access it by mistake.
This guide for my own reference please don’t rely on it, for a better introduction check out Git Reference website. Basic concept and terminologies, Git have 3 logical places:
Working Area: normal directory where you edit your project.
Staging Area: Think of the staging as your project state before you start your coding session, after each coding session you add your changes to staging area using “git add filename” or “git add .”
Snapshot Area: After multiple coding sessions you would finish a logical change, e.g. adding commenting system in web site, next you need to store a snapshot of your project after these changes, you would do that with “git commit”
vi .gitignore # files you want Git to ignore, e.g. log, tmp, binaries
git init # Initalize Git
git add . # Add All files to Git tracking
git commit # Initial commit, get a snapshot of the project
git status -s # Get the status of files changed
git add README # Add README to staging area
git commit -m "Describe your change" # Make a snapshot of the staging area