We came across Bonfire while looking for an authentication library for CodeIgniter to help us kick start a web application we're about to start. Bonfire is a framework built on top of CodeIgniter. It'...
If you're a web developer and you're not using Distributed Version Control System (DVCS), you fall into two categories: 1) You are scared of change or 2) You have found something even better such as flying over the moon on a spoon.
DVCS's allow everyone to all have their own clones/copies of the source code, and branch to their hearts content. You can commit your changes locally and then push them back to a central cloud hosted service when you feel the code is of value to others, then other users can then fetch your updates and enhance the source code.
So where do you start?
I recommend you head on over and download yourself a cheatsheet from Github itself to help you when you're feeling lonely.
First things first, you need to makesure that git is installed and accessible via the command line. We're not going to run through those steps here. Ok, so git is working on the command line, let's proceed.
> git init
This will tell git to start recording all changes with it's magical wand.
Git will monitor all changes, however, you must tell it what to do with the changes.
> git status
You should be able to see all changes since the original initialization/last commit. Such as: files not added, files updated, files deleted etc.
# You have two options here, inline commenting, # or adding a comment through default command line # editor such as vim > git commit -a #or through editor > git commit -m "My first commit"
When you commit your changes, git requires that your file has been added to the list of files it should keep it's version history.
#Schedules all files to be added to the next commit > git add .
This is fantastic, now you can add one file at a time if you like, or all of them just by typing the fullstop. But how do you ignore files to be added? Such as nasty cache folders or files specifically for IDE projects.
# .gitignore file on root folder config/db_connection.ini
Modify the .gitignore folder in webroot. and add the filenames of the files you wish to not include. This can be very handy for password files. It's always best to save a dummy version for new users as a guide to help them set up their config options manually, and ignore your actual config file with passwords.
Another sweet magic trick git does is Branches, lets try that.
# Create a new branch and inherit all the files from # current branch > git branch branchname # eg. git branch awesomeNewFeature
So what happens now is that a new branch is created inheriting all the files from the current branch. You are now free to use that branch to test and add/update/delete whatever files you want and revert back to your master branch whenever you want. You'll find that down the track you may have separate branches for dev/uat/prod and individual features that you may wish to merge.
> git checkout branchname # eg. git checkout awesomeNewFeature
By getting an update again, you should see the branch name now at the end of the current folder location. All changes made are only relevant to this branch, you can go back to your master branch at any time
> git checkout master
# make sure you are currently in the folder you wish to add # the repository to > git clone http://gitdomainname.com/gitproject.git
You will be asked for username and password, afterwards, sit back and watch the files fly.
# Pull and merge changes > git pull http://domainname/gitproject.git
This will merge the files that have changed, and with luck you shouldn't have to manually go back a manually resolve them.
# Commit your work locally you crazy banana # > commit -a "I have done the changes required, bedtime awaits" > git push http://domainname.com/gitproject.git
Your changes should now be available for others to pull and clone in safety.
There are heaps and heaps more commands at your disposal, I hope this brief introduction is of help to you.
Good luck in your travels.
Update - 05/09/12
Standard list of extensions to add to gitignore
# Numerous always-ignore extensions
# OS or Editor folders
# Dreamweaver added files
# Folders to ignore