A Tutorial For GitHub
A Tutorial For GitHub
GitHub
Xiao Li
Department of Informatics
University of Zurich
Agenda
Why use Version (Source) Control Systems
What are Git and GitHub
Basic Git Commands
Fundamentals of GitHub
Using GitHub in Project Implementation
Why version control?
Scenario 1:
Your program is working
You change “just one thing”
Your program breaks
You change it back
Your program is still broken--why?
4
Version control for teams
Scenario:
You change one part of a program--it works
Your co-worker changes another part--it works
You put them together--it doesn’t work
Some change in one part must have broken something in the
other part
What were all the changes?
5
Teams (part 2)
Scenario:
You make a number of improvements to a
class
Your co-worker makes a number of different
improvements to the same class
How can you merge these changes?
6
Version control systems
A version control system (often called a source code
control system) does these things:
Keeps multiple (older and newer) versions of everything (not
just source code)
Requests comments regarding every change
Allows “check in” and “check out” of files so you know which
files someone else is working on
Displays differences between versions
7
Benefits of version control
For working by yourself:
Gives you a “time machine” for going back to earlier versions
Gives you great support for different versions (standalone, web
app, etc.) of the same basic project
For working with others:
Greatly simplifies concurrent work, merging changes
8
What are Git and GitHub
Git is a free and open source distributed version control
system designed to handle everything from small to very
large projects with speed and efficiency
GitHub is a web-based Git repository hosting service,
which offers all of the distributed revision control and
source code management (SCM) functionality of Git as
well as adding its own features.
How to setup Git and GitHub
Download and install the latest version of GitHub
Desktop. This will automatically install Git and keep it up-
to-date for you.
https://help.github.com/articles/set-up-git/
BASIC GIT COMMANDS
Introduce yourself to Git
On your computer, open the Git Shell application.
Enter these lines (with appropriate changes):
git config --global user.name "John Smith"
git config --global user.email jsmith@seas.upenn.edu
14
Making commits
You do your work in your project directory, as usual
If you create new files and/or folders, they are not tracked by Git unless you ask it to do so
git add newFile1 newFolder1 newFolder2 newFile2
Committing makes a “snapshot” of everything being tracked into your repository
A message telling what you have done is required
git commit –m “Uncrevulated the conundrum bar”
git commit
This version opens an editor for you the enter the message
15
Commits and graphs
A commit is when you tell git that a change (or addition) you have made is
ready to be included in the project
When you commit your change to git, it creates a commit object
A commit object represents the complete state of the project, including all the files in
the project
The very first commit object has no “parents”
Usually, you take some commit object, make some changes, and create a new commit
object; the original commit object is the parent of the new commit object
Hence, most commit objects have a single parent
You can also merge two commit objects to form a new one
The new commit object has two parents
Hence, commit objects forms a directed graph
Git is all about using and manipulating this graph
16
Commit messages
In git, “Commits are cheap.” Do them often.
When you commit, you must provide a one-line message
stating what you have done
Terriblemessage: “Fixed a bunch of things”
Better message: “Corrected the calculation of median scores”
18
Keeping it simple
If you:
Make sure you are current with the central repository
Make some improvements to your code
Update the central repository before anyone else does
Then you don’t have to worry about resolving conflicts or working
with multiple branches
All the complexity in git comes from dealing with these
Therefore:
Make sure you are up-to-date before starting to work
Commit and update the central repository frequently