Git & GitHub
Getting Started Workshop
originally by Gwen Lofman
modified by Greg Willard
Follow along with the slides at
polyhacks17.github.io/github-workshop
Shortened link: goo.gl/53L48V
Scope
- up and running with
git gitas a standalone usergitas a participant
Command Syntax
command subcommand -o --option
Navigating the file system
cd- change directoryls- list files & directoriesmkdir- make directory
What is git?
This is an example of bad version control.
This is an example of good version control.
Up and Running
Installation
Linux usually comes with git installed
Linux
(Ubuntu/Debian)
Getting Help
git help or documentation at git-scm.com/doc
You can get help for individual commands withgit help [command]
Git also has an extensive manual withman git
Configuration
git needs to know who you are.
Why does git need my name?
Git associates every change with a name and email so you can tell who changed what.
Using git as a standalone developer
A mental model for staging
You don't want to make a commitment until everything is ready.
The git commit workflow
- Each commit is a patch
- You must prepare a commit before finalizing it
- Each commit is a unit of work, put related changes together.
A git repository is a directory on your computer.
Your .git folder holds the internals of git.
git status shows the status of your repository.
git status gives suggestions about what to do next.
git diff shows untracked changes inside your files
git add stages changes
Stage relevant changes together
git add -p lets you add parts of a file.
git reset HEAD -- unstages changes
git commit adds a change to the history
Apply all of your staged changes. esc :x leaves the editor.
git commit takes a message that describes the patch. Writing a good message is key:
- Write in present imperative, for example:
Add README.md to describe projectImplement improved error handling, fixes #13- Think of commit messages like emails
- Describe not just what, but why
git log shows your past changes.
git revert undoes changes
Using git as a participant
git is distrubuted version control.
Different participants in a project can share changes between each-other
git branch lets you work on changes in isolation
One feature to rule them all!
A mental model for branches
Like a branch on a family tree.
NOTE: checking out a branch changes the files in your repository.
git stash let's you save changes for later
To bring changes back from your stash: git stash apply
Manipulating Branches
How do I get changes from one branch to another?
git mergegit rebase
This is typically what happens with a git merge.
A mental model for merging
Integrate changes
Sometimes git can fast-forward
Now to the GitHub part!
Let's get interactive!
Sign up at GitHub.com/join