2. WHAT IS SCM?
SOURCE CODE MANAGEMENT
• Storing versions of files
• Good backup
• Important when working in teams
• Points to revert back to
Thursday, 30 May 13
3. SCM SYSTEMS
SOME EXAMPLES
• Mercurial
SUPER QUICK, LARGE DEV-TEAMS, SIMPLE
• Subversion
WIDEST ADOPTION, CHECKING OUT FILES, CENTRAL SERVER
• Git
GROWING QUICKLY, SUPER FAST, DELTA CHANGES, GITHUB, AWESOME
Thursday, 30 May 13
4. GIT VS GITHUB
• Distributed source code management
system
• Hosted solution to facilitate easy
collaboration on Git repositories
Thursday, 30 May 13
5. WHY GIT?
• Distributed
• Super-fast
• Lightweight
• Server-less
• Personal preference
• GitHub
Thursday, 30 May 13
6. WHY GIT?
• Distributed
• Super-fast
• Lightweight
• Personal preference
• GitHub
Thursday, 30 May 13
7. WHY GIT?
• Distributed
• Super-fast
• Lightweight
• Personal preference
• GitHub
Thursday, 30 May 13
8. WHY GIT?
• Distributed
• Super-fast
• Lightweight
• Personal preference
• GitHub
Thursday, 30 May 13
9. WHY GIT?
• Distributed
• Super-fast
• Lightweight
• Personal preference
• GitHub
Thursday, 30 May 13
10. WHY GIT?
• Distributed
• Super-fast
• Lightweight
• Personal preference
• GitHub
Thursday, 30 May 13
11. GITHUB, GITHUB, GITHUB
MORE ON THIS MAGICAL TOOL
• Git repository hosting
• Web tool suite
• Collaborative development
• Social coding (forking)
Thursday, 30 May 13
12. INSTALLING GIT
HANDS-ON #1
MAC
<3 - Easy as pie
WINDOWS
Good luck
https://help.github.com/articles/set-up-git
Thanks GitHub, let’s visit:
Thursday, 30 May 13
13. GIT WORKFLOW
$ cd ~/Desktop/
$ mkdir git
cd is the unix command for
‘change directory’. ~/ is
your home directory.
mkdir is the unix command
for ‘make directory’. The
same thing as creating a
new folder.
Thursday, 30 May 13
14. GIT WORKFLOW
git init will turn the current
folder into a git repository.
Git will now monitor this
folder and any files and
sub-directories for changes
$ cd ~/Desktop/
$ mkdir git
$ cd git
$ git init
Thursday, 30 May 13
15. GIT WORKFLOW
git status tells you the
current status of the
repository (changed files
etc)
Now: open up your text
editor and create a blank
txt file. Save it in the same
directory as your git repo.
$ git init
$ git status
Thursday, 30 May 13
16. GIT WORKFLOW
git status will now tell you
there are untracked files
git add [filename] is used to
add files to the stage for a
commit
$ git status
$ git add hello.txt
Thursday, 30 May 13
17. WOAH, SLOW DOWN!
SOME GIT TERMINOLOGY
STAGE
A SET OF “STAGED” CHANGES THAT WILL BE PART OF A
COMMIT
COMMIT
A PERMANENT SNAPSHOT OFYOUR GIT REPOSITORY AT A
GIVEN TIME
Thursday, 30 May 13
18. GIT WORKFLOW
git commit will create a
snapshot of your repository
saving all staged changes
We use the -m flag
followed by a string to
define a commit message.
Keep in mind that unstaged
changes won’t be saved.
$ git status
$ git add hello.txt
$ git commit -m “Initial commit”
Thursday, 30 May 13
19. GIT WORKFLOW
git status will show no
changes
1. Make a change to
hello.txt
2. Make a new file
3. Commit JUST the new
file
$ git status
$ git add hello.txt
$ git commit -m “Initial commit”
$ git status
Thursday, 30 May 13
21. TEAM WORKFLOW
USING GIT & GITHUB
• Role-oriented AND random editing of files
without fear of overwriting anyone else’s work
• Branching off from the master (main) code base to
work on individual features WITHOUT breaking
the whole site
• Multiple backups of the code-base
• Ability to revert to ANY previous version of a file
Thursday, 30 May 13
22. ‘ADVANCED’ TERMINOLOGY
PUSHING
PUSHYOUR COMMITS TO THE UPSTREAM SERVER (GITHUB)
PULLING
PULL DOWN THE LATEST COMMITS FROM THE UPSTREAM SERVER (GITHUB)
MASTER BRANCH
MASTER IS THE DEFAULT BRANCH INYOUR REPOSITORY.THIS IS THE MAIN CODE BASE
AND SHOULD AT ALL TIMES CONTAIN DEPLOYABLE CODE.
BRANCHING
CREATING ADDITIONAL BRANCHES OFF OF MASTER TO WORK ON INDIVIDUAL FEATURES
Thursday, 30 May 13
23. PUSHING & PULLING
USING AN UPSTREAM SERVER (GITHUB)
• In your teams: push and pull as often as
possible
• Before starting work on, always PULL
• Try to use another communication tool (FB,
Skype etc) to keep in touch when developing
and tell eachother when you have made
changes.
Thursday, 30 May 13
24. OH SHIT!
SOMEONE EFFED’ UP
•You probably went to push some commits
without pulling from GitHub and now you have
some screwed up, out of order repo.
•Solving this problem can be a bitch so cross
your fingers and hope for the best.
Thursday, 30 May 13
25. OH SHIT!
THE SOLUTION
• Run git pull. Git will force you to merge
the changes but you will need to do this
manually.
• Run git merge. Git will merge your
commits with the upstream commits into
a new commit, then push.
Thursday, 30 May 13
26. BRANCHING
SOME GIT AWESOMENESS
• Branching should be used when you want to
work on a specific feature
• Give your branches descriptive names
i.e. user-login or pretty-forms
• Don’t try and make your branches all
encompassing (keep them small and modular)
Thursday, 30 May 13
28. TEAM WORKFLOW
BRANCHING, PULL REQUESTS & MERGING
• Get in your teams
• The technical lead should create a repository on
their account then go to settings and invite the
other members of your team as collaborators.
• Everybody grab the URL found on the repo page:
Thursday, 30 May 13
29. BRANCHING
$ cd ~/Desktop/
$ git clone https://github.com/
codycarnachan/mds.git
Let’s reset our directory to
our Desktop.
git clone is the command
for cloning a repository.
Make sure you put your
own URL in; you won’t be
able to clone repositories
that you aren’t a
collaborator on.
Thursday, 30 May 13
30. BRANCHING
$ cd ~/Desktop/
$ git clone https://github.com/
codycarnachan/mds.git
$ git checkout -b new-branch-
name
git checkout -b
[branchname] is the
command for creating a
new branch and switching
to it (or just switching if it
already exists)
Changes you make now will
be independent to the
master brach
Thursday, 30 May 13
31. BRANCHING
$ cd ~/Desktop/
$ git clone https://github.com/
codycarnachan/mds.git
$ git checkout -b new-branch-
name
Create a file with some
text and then commit it.
Note: There is a different
format to push your new
local branch to the
upstream server:
git push -u origin
[branchname]
Thursday, 30 May 13
32. TEAM WORKFLOW
BRANCHING, PULL REQUESTS & MERGING
• You can checkout each others branches to test
features that might be in progress.
• Once you have a branch with code that is ready to
get merged into master. Go to the GitHub page >
Branches > Click on the branch and then Click Pull
Request
• The Technical Lead should be responsible for
merging pull requests to keep everything streamlined.
Thursday, 30 May 13
34. FURTHER READING
• A general guide to pushing/pulling
http://tinyurl.com/c3yr2v
• What to do when master is ahead of you
http://tinyurl.com/nh9jt2t
• Basic overview of branching and merging
http://tinyurl.com/btwgu79
• Setting up Git at home
https://help.github.com/articles/set-up-git
Thursday, 30 May 13