Aside from being the version control system that powers Drupal development, Git is the VCS of choice for most modern software development, at least on the web -- as well as a must-have skill for any Drupal developer seeing a job. (Lack of experience with Git is my number one frustration with developers I work with.)
But because of its distributed nature (i.e., every copy of the repository is complete unto itself and doesn't necessarily need an authoritative central system), Git presents conceptual challenges not only to beginners but to developers experienced with older forms of version control -- RCS, CVS, SVN, etc.
In this session, we'll look at the basic concepts behind Git, including:
Why I need version control even if I work alone in my closet and never see anyone else.
Who's in charge here?!: Understanding Distributed VCS
All hail the SHA
My repository, remote repositories
Pushing and Pulling
Finally we'll look at the vary basic tasks of cloning or initializing a repository and committing to it, then pushing your changes back to a server.
2. ABOUT ME
• Freelance Drupal Developer
and Web Generalist since 1997
• Drupal since 4.6
• Most Definitely Available for Work!
matt@wrathercreative.com
(510) WRA-THER
3. SOURCES
• A great talk by @merlyn himself, Randal Schwartz CC-BY-SA
• OnVimeo at https://vimeo.com/35778382
• Slides at http://slidesha.re/z7nQrG
• Pro Git by Scott Chacon CC-BY-NC-SA
• Read for free at http://git-scm.com/book
• And many more at http://lmgtfy.com/?q=git+tutorial
4. AGENDA
1. Why UseVersion Control
2. Git basic concepts
3. Demo
Time for questions after each section.
7. WHAT IS GIT FOR?
Git is for…
• Tracks a tree of related files
• Distributed
• High Performance
• Easy & Fast Branch/Merge
• Good Data Integrity
• Collaborative
Git is not for…
• Tracking unrelated files
• Tracking File Metadata
• Binary Files
8. WRAPYOUR MIND AROUND
• Distributed:Your repository is complete unto itself.
• Anyone can commit!*
*To their own repo.
• (Once you start fetching and pushing work,
permissions come into play.)
• There can still be a central, blessed repo.
• Universal Public Identifiers: SHA1 hashes
9.
10. OBJECTS IN GIT
• Blobs (actual data)
• Trees (directories of blobs or of other trees)
• A commit, which is:
• A tree
• Zero or more parent commits
• Metadata (commit message, name email, timestamp)
12. WE NEEDTOTALK
ABOUT COMMITMENT
Do this
Work
Stage
Commit
here
Filesystem
Staging Area
Repository
(aka here)
WorkingTree
Index
HEAD
by
writing code
git add
git commit
Rinse and Repeat
34. graphic from Pro Git by Scott Chacon
CC-BY-NC-SA
REBASING
$ git checkout experiment
$ git rebase master
35. Thou shalt not rebase commits that you
have pushed to a remote repository.
36. REMOTE REPOSITORIES
• All these things that we’ve done so far happen in the privacy
of our own computer and don’t affect anything else.
• You can track what’s going on in other repositories by adding
them as “remotes”
git remote add <nickname> <remote-url>
• When you copy a repo using the git clone command,
you’ll automatically have a remote called origin
37. REMOTE REPOSITORIES
• When you’ve done working, you can “push” your work up to a
remote repository
git push <remote-nickname> <branch>
git push origin master
• But if someone else has done work and pushed it to the
remote repo, git won’t let you overwrite.
38. REMOTE REPOSITORIES
• To find out what’s on the server, you can “fetch” from a
remote repository
git fetch <remote-nickname>
git fetch origin
• Remote branches will be tracked locally, prefixed with the
remote nickname.The master branch on origin becomes
origin/master locally.