After talking to several Drupal followers during our last meetup, I realised quite a few people still don't employ version control.
I strongly consider this best practice when building a site, and thought it would be a good opportunity to go over its importance and how you can make it work for you.
Git offers several advantages:
• It's super fast
• It's easy.
• And no you don't need to be familiar with Command Line code (there are several great GUI's out there).
GIT Version Control works by keeping track of all successive changes you make to a site.
The biggest advantage of this is easily undoing any mistakes you might make along the way.
It's a great feeling to know Version Control has your back that you can roll back if something goes catastrophically wrong.
It's also a big bonus in collaborative development.
As soon as more than one person works on a project things get a lot more complicated.
What happens when 2 edits effect the same file? How do you know what's new, what's old and what's changed?
No worries, simply merge the variations and let GIT deal with the rest.
GIT is not just for the developers of this world but can be a life saver for themers, site maintainers and the like.
Most people will admit they should use it, but either don't know how or believe it's hard to integrate.
The reality is that it's actually pretty simple and once you start integrating GIT into your workflow you'll ask yourself "Why the hell did I keep using ftp" - I know I did.
FTP is so yesterday, its slow, it's cumbersome to use and it's a very manual method.
Switch to GIT, start using GIT, and never look back.
2. Who am I
• Gareth Hall
• Lead Developer and Hyundai New Zealand
• Director at Communica
(http://communica.co.nz)
3. What is git?
• Git is a distribute version control system
developed by Junio Hamano & Linus
Torvalds.
• Git does not use a centralised server.
• Git runs on major operating system like OS
X, Windows, Unix & Linux
4. Why it’s named git?
• Quoting Linus: “I’m egotistical, and I name
all my projects after myself. First Linux, now
git”
• Def: git - British slang for “pig headed, they
are always correct , argumentative”
6. Advantages of git
• Everything is local (almost)
• Fast
• Every clone / branch is a backup
• Work offline
• No single point of failure
• Lightweight
• Branching is cheap and merging is easy
• Many different workflows possible
• Distributed
• Every file and commit is checksummed
• Staging area
• Free and open source
13. git init
•Create an empty git repository or reinitialize
an existing one
#:>git init
Initialized empty Git repository in
/Users/garethhall/Sites/git_intro/.git/
14. git status
• Show the working tree status
#:>git status
# On branch master
#
# Initial commit
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# includes/
# index.php
nothing added to commit but untracked files present (use "git add" to track)
15. git add
• Add file contents to the index
• git add .
• git add <filename> <filenname>
16. git status
#:>git add .
#:>git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached <file>..." to unstage)
#
# new file: includes/helpers.php
# new file: index.php
#
20. #:>git status
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: includes/helpers.php
# modified: index.php
#
no changes added to commit (use "git add" and/or "git commit -a")
21. #:>git add index.php
#:>git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: index.php
#
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: includes/helpers.php
#
22. • #:>git commit -m "Changed output to table"
[master fffacb4] Changed output to table
1 file changed, 10 insertions(+), 2 deletions(-)
#:>git status
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: includes/helpers.php
#
no changes added to commit (use "git add" and/or "git commit -a")
23. #:>git log
commit fffacb43627c5a44850b4b1543dc359f5d95edd6
Author: Gareth Hall <gareth@communica.co.nz>
Date: Sat Feb 16 16:10:45 2013 +1300
Changed output to table
commit 5f8a8d486ae1656b51194186c0dfb97ae1ec9835
Author: Gareth Hall <gareth@communica.co.nz>
Date: Sat Feb 16 14:43:40 2013 +1300
first commit
28. git checkout
•Checkout a branch or paths to the working tree
#:>git checkout outputHelper
Switched to branch 'outputHelper'
#:>git branch
master
* outputHelper
30. #:>git status
# On branch outputHelper
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: includes/helpers.php
# modified: index.php
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# includes/.DS_Store
# includes/output_helper.php
no changes added to commit (use "git add" and/or "git commit -a")
31. #:>git add includes/helpers.php
#:>git commit -m 'Added doc block to logger function'
[outputHelper df78fc4] Added doc block to logger function
1 file changed, 8 insertions(+)
#:>git commit -a -m 'Refactored with new table output helper'
[outputHelper 51da4b7] Refactored with new table output helper
3 files changed, 38 insertions(+), 11 deletions(-)
create mode 100644 includes/.DS_Store
create mode 100644 includes/output_helper.php
32. #:>git log --oneline --decorate --graph
* 51da4b7 (HEAD, outputHelper) Refactored with new table output helper
* df78fc4 Added doc block to logger function
* 817dee6 (master) Added logger
* fffacb4 Changed output to table
* 5f8a8d4 first commit
#:>git checkout master
Switched to branch 'master'
#:>git log --oneline --decorate --graph
* 817dee6 (HEAD, master) Added logger
* fffacb4 Changed output to table
* 5f8a8d4 first commit
33. git merge
• Join two or more development histories together
#:>git merge outputHelper
Updating 817dee6..51da4b7
Fast-forward
includes/.DS_Store | Bin 0 -> 6148 bytes
includes/helpers.php | 8 ++++++++
includes/output_helper.php | 36 ++++++++++++++++++++++++++++++++++++
index.php | 13 ++-----------
4 files changed, 46 insertions(+), 11 deletions(-)
create mode 100644 includes/.DS_Store
create mode 100644 includes/output_helper.php
34. #:>git log --oneline --decorate --graph
* 51da4b7 (HEAD, outputHelper, master) Refactored with new
table output helper
* df78fc4 Added doc block to logger function
* 817dee6 Added logger
* fffacb4 Changed output to table
* 5f8a8d4 first commit