0% found this document useful (0 votes)
18 views72 pages

01 03 Version Control

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views72 pages

01 03 Version Control

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 72

Course Announcements

● Due dates
○ Student survey “due” tonight
○ Due next Friday (released by 11:59 PM tonight):
■ D1 (discussion lab)
■ Q1 (Canvas quiz)
■ A1 (Assignment)
■ Group submission (1 form/group)
● Discussion Section today (this week is for finding group mates)
Version Control
Shannon E. Ellis, Ph.D
UC San Diego
Department of Cognitive Science
[email protected]
This sucks
Yup, this sucks too.

adapted from Brad Voytek


This is a step in the right direction
Version Control
● Enables multiple people to simultaneously work on a single project.

● Each person edits their own copy of the files and chooses when to share those
changes with the rest of the team.

● Thus, temporary or partial edits by one person do not interfere with another
person's work

adapted from Brad Voytek


What is version control?
A way to manage the evolution of a set of files
What is version control?
A way to manage the evolution of a set of files
File1_

v1 v2 v3
What is version control?
A way to manage the evolution of a set of files
File1_

v1 v2 v3
File2_

v1 v2 v3 v4 FINAL FINALfinal
What is version control?
A way to manage the evolution of a set of files

When using a version control system, you have one


File1 copy of each file and the version control system
tracks the changes that have occurred over time

File2
What is version control?
A way to manage the evolution of a set of files
The set of files is
referred to as a
File1 repository (repo)

File2
https://insights.stackoverflow.com/survey/2017#work-version-control
git & GitHub

GitHub (or Bitbucket or GitLab) is the


the version control system home where your git-based projects
live on the Internet.
~ Track Changes
from Microsoft
Word….on steroids ~ Dropbox….but
way better
What version control looks like
$ git clone https://www.github.com/username/repo.git
$ git pull
$ git add -A
$ git commit -m “informative commit message”
$ git push

Terminal
GitHub
GUIs can be helpful when working with version control

GitHub Desktop SourceTree


Version Controller

How do you typically interact with git?


A B C D E
I don’t command GUI: GUI: GUI:
line GitHub SourceTree other
Desktop
Why version control with git and GitHub?

Tracking
Returning to Exposure for
Collaboration others’ work
a safe state your work
Collaborate like you do with Google Docs

GitHub repository

Collaboration
Each person is making changes locally
(on their computer)
Make changes locally, while knowing a stable copy exists

Returning to You’re free and safe to try


a safe state things out locally. You’ll only
send changes to the repo
when you’re at a stable point
Your repositories will be visible to others!

Exposure for Your public GitHub repos


your work are your coding social
media
Keep up with others’ work easily

Tracking
others’ work As a social platform, you
can see others’ work too!
A GitHub repo contains all the files
and folders for your project.
File1
repo repo
File2

GitHub is a remote
host. The files are
geographically distant
from any files on your
computer.
File1 When you first make a
repo copy onto your local
repo clone computer (read: laptop),
File2 you clone the repository.
File1
repo repo clone
File2

clo If someone else on your project


cloned the repo at the same time,
ne
you would have identical copies of
the project on each of your
computers.
File1
repo repo clone
File2

clo
ne

Yay! Everyone can


work on the project!
File1
repo repo You decide you want to
change a few of the
File2 images in the project.
File1
repo repo You decide you want to
change a few of the
File2 images in the project.

Car goes real


Car goes fast.
fast. Car goes
Car goes beep.
beep.
car.txt

Prof sleeps like


Prof sleeps like a rock. That’s
a rock. why she has so
much energy in
the AM..
prof.txt
File1
repo repo
File2

Car goes real


Car goes fast.
fast. Car goes
Car goes beep.
beep.
car.txt car_new.txt

Prof sleeps like


Prof sleeps like
a rock. That’s without git...you’d
a rock. why she has so
much energy in likely rename
these files….
the AM..
prof.txt prof_new.txt
File1
repo repo
File2

Car goes real


Car goes fast.
fast. Car goes
Car goes beep.
beep.
car.txt car_new.txt

Prof sleeps like


Prof sleeps like
a rock. That’s Thank goodness
a rock. why she has so
much energy in those days are
over!
the AM..
prof.txt prof_new.txt
File1
repo repo
File2

Car goes real


Car goes fast.
fast. Car goes
Car goes beep.
beep.
car.txt

Prof sleeps like


a rock. That’s Instead, you tell git which files
Prof sleeps like
a rock. why she has so you’d like to keep track of
much energy in
the AM.. using add. This process is called
prof.txt staging.
git add file stages specified file (or folder)
git add . stages new and modified files
File1
git add -u stages modified and deleted files
repo repo git add -A stages new, modified, and deleted files
File2 git add *.csv Stages any files with .csv extension
git add * Use with caution: stages everything

Car goes real


Car goes fast.
fast. Car goes
Car goes beep.
beep.
car.txt

Prof sleeps like


a rock. That’s Instead, you tell git which files
Prof sleeps like
a rock. why she has so you’d like to keep track of
much energy in
the AM.. using add. This process is called
prof.txt staging.
File1
repo repo
File2

Car goes real


Car goes fast.
fast. Car goes
Car goes beep.
beep.
car.txt

Prof sleeps like


Prof sleeps like a rock. That’s
why she has so
a rock.
much energy in Then, you create a snapshot of
the AM.. your files at this point. This
prof.txt snapshot is called a commit.
File1
repo repo
File2

Car goes real


Car goes fast.
fast. Car goes
Car goes beep.
beep.
car.txt

Prof sleeps like


Prof sleeps like a rock. That’s
why she has so
a rock.
much energy in Then, you create a snapshot of
the AM.. your files at this point. This
prof.txt snapshot is called a commit.

A commit tracks
who, what, and
when
File1
You can make commits more
repo repo informative by adding a
File2
commit message.

Example: git commit -m 'fix


Car goes real
typos in car and prof'
Car goes fast.
fast. Car goes
Car goes beep.
beep.
car.txt

Prof sleeps like


Prof sleeps like a rock. That’s
why she has so
a rock.
much energy in Then, you create a snapshot of
the AM.. your files at this point. This
prof.txt snapshot is called a commit.

A commit tracks
who, what, and
when
File1
repo repo
File2

Shannon Ellis
3/28/21 3:28pm
fix typos in car and prof
File1
repo repo
File2

pus
h
Remember, you’re not the only one
working on this project though! You want
your teammates to have access to these
changes! You push these changes back to
the remote.

Shannon Ellis
3/28/21 3:28pm
fix typos in car and prof
File1
repo repo
File2

Shannon Ellis
3/28/21 3:28pm
fix typos in car and prof

Your teammate is still


working with the
(out-of-date) copy he
cloned earlier!

Shannon Ellis
3/28/21 3:28pm
fix typos in car and prof
File1
To catch up, your teammate will have to
repo repo pull the changes from GitHub (remote)
File2

Shannon Ellis
3/28/21 3:28pm
fix typos in car and prof

Your teammate is still


working with the
(out-of-date) copy he
cloned earlier!

Shannon Ellis
3/28/21 3:28pm
fix typos in car and prof
File1
repo repo
File2

pu
ll

Your teammate pulls


from remote and is now
up-to-date!

Shannon Ellis
3/28/21 3:28pm
fix typos in car and prof
File1
repo repo cow.png

File2

pu
ll bunny.png

The files in his project


locally will now have
the updated images

Your teammate pulls


from remote and is now
up-to-date!

Shannon Ellis
3/28/21 3:28pm
fix typos in car and prof
File1

clone
Let’s recap real quick!
repo
local
File2
host
remote
host repo - set of files and folders for a project
remote - where the repo lives
clone - get the repo from the remote for the first time
pu
sh add - specify which files you want to stage (add to repo)
pu

commit - snapshot of your files at a point in time


ll

pull - get new commits to the repo from the remote


push - send your new commits to the remote

commit
Review & Question Time
Version Controller I
You’ve been working with a team on a project in a repo. You’ve
made changes locally and you want to see them on the remote.
What do you do to get them on the remote?

A B C D E
clone remote merge pull push
Version Controller II
Your teammate has given you access to a GitHub repository to
work on a project together. You want to get them for the first
time on your computer locally.
What do you do to get the repo on your computer?
A B C D E
clone remote commit pull push
Each time you create a commit, git tracks
the changes made automatically.

is
ys
al
an
al
iv
rv
su
lis

m
8p ude
El

:0 l
n

15 nc
no

/2 to i
an

28
Sh

3/ ite
d
ed
of
pr
m and
lis

8p
El

:2 r
ca
n

13
no

n
/2 si
an

28 po
Sh

3/ ty
fix
s
fi le

tin
m
1a ysis

ar
1:1

M
l
11 na

la
/2 ed a

ge
26

An
3/ ud
cl
In
File1

File2

ne
repo am

alo
10 it
9:

M
8 m

n
/1 m
repo

vi
26 co

Ke
3/ al
iti
In
File1
By committing each time you make
repo repo changes, git allows you to time travel!
File2
File1
By committing each time you make
repo repo changes, git allows you to time travel!
File2

377dfcd00dd057542b112cf13be6cf1380b292ad

439301fe69e8f875c049ad0718386516b4878e22

There’s a unique id, known as a 456722223e9f9e0ee0a92917ba80163028d89251

hash, associated with each


commit.
File1 You can return to the state of the
repo repo repository at any commit. Future commits
don’t disappear. They just aren’t visible
File2
when you check out an older commit.

377dfcd00dd057542b112cf13be6cf1380b292ad
File1 But...not everything is always linear.
repo repo Sometimes you want to try something out
and you’re not sure it’s going to work. This
File2
is where you’ll want to use a branch.

main branch

try-something-cool
It’s a good way to experiment. It’s
File1
pretty easy to get rid of a branch later
repo repo on should you not want to include the
File2 commits on that branch.

main branch

try-something-cool
But...what if you DO want to
File1
include the changes you’ve made
repo repo on your try-something-cool branch
File2 into the main branch?

main

try-something-cool
A merge allows you to combine
File1
the commits from a branch back
repo into the main.
repo
File2

main

try-something-cool
fork
someone your
else’s repo GitHub

What if someone else is working


on something cool and you want
to play around with it? You’ll have
to fork their repo.
fork clone
someone your
else’s repo GitHub
pus
h
pul
l

commit

After you fork their repo, you can


play around with it however you
want, using the workflow we’ve
already discussed.
fork clone
someone your
else’s repo GitHub
pull req
uest

commit

But what if you think you’ve found a bug in


their code, a typo, or want to add a new feature
to their software? For this, you’ll submit a pull
request (aka PR).
fork clone
someone your
else’s repo GitHub
pull req
The author then uest
reviews your
code/edits and
decides whether or
not they want to commit
merge your pull
request.

But what if you think you’ve found a bug in


their code, a typo, or want to add a new feature
to their software? For this, you’ll submit a pull
request (aka PR).
someone
else’s repo

Last but not least...what if you find


a bug in someone else’s code OR
you want to make a suggestion but
aren’t going to submit a suggestion
with a PR. For this, you can file an
issue on GitHub.
Issues are bug trackers. While,
someone
else’s repo
they can include bugs, they can
also include feature requests,
to-dos, whatever you want,
Last but not least...what if you find really!
a bug in someone else’s code OR
you want to make a suggestion but They can be assigned to people.
aren’t going to submit a suggestion
with a PR. For this, you can file an They can be closed once
issue on GitHub. addressed ….or if the software
maintainer doesn’t like the
suggestion
commits allow you to time travel
377dfcd00dd057542b112cf13be6cf1380b292ad because each commit is assigned a
unique hash

One more git recap...


commits allow you to time travel
377dfcd00dd057542b112cf13be6cf1380b292ad because each commit is assigned a
unique hash

main branch
branches allow you to
experiment. branches can be
try-something-cool abandoned or merged

One more git recap...


commits allow you to time travel
377dfcd00dd057542b112cf13be6cf1380b292ad because each commit is assigned a
unique hash

main branch
branches allow you to
experiment. branches can be
try-something-cool abandoned or merged

fork
You can work on others’ repos
someone your by first forking their repository
else’s repo GitHub onto your GitHub

One more git recap...


commits allow you to time travel
377dfcd00dd057542b112cf13be6cf1380b292ad because each commit is assigned a
unique hash

main branch
branches allow you to
experiment. branches can be
try-something-cool abandoned or merged

fork
You can work on others’ repos Pull requests allow you to make
someone your by first forking their repository specific edits to others’ repos
else’s repo GitHub onto your GitHub

Issues allow you to make general


suggestions to your/others’ repos
One more git recap...
Review & Question Time
Version Controller III

To experiment within your own repo (test out a new feature, make
some changes you’re not sure will work)...

what should you do?

A B C D E
hash branch merge fork pull request
Version Controller IV

If you’ve made edits to someone else’s repo that you’re not a collaborator on…

what would they have to do to incorporate your changes?

A B C D E
hash branch merge fork pull request
Version Control: Practice
- Discussion Lab 1: Part 3
- Assignment 1: Part 1
- This will get you practice with git & GitHub
- Understand what you’re doing in the assignment!
- You may have to google, ask others, spend some time with this!
- Part II is a Python review; each part of this assignment is self-contained
- Do this part of the assignment ASAP
Note: You’re encouraged to
- git & Github == How to get the course lectures/materials
- Assignment 1 will have you fork the Lectures and Project repos
put projects on GitHub.
- You can keep the lectures up-to-date throughout the quarter Please do not put
- you’ll be using GitHub for your final projects assignments on GitHub.
COGS 108 Final Projects
The COGS 108 Final Project will give you the chance to explore
a topic of your choice and to expand your analytical skills. By
working with real data of your choosing you can examine
questions of particular interest to you.
- You are encouraged to work on a topic that matters to the world (your family, your neighborhood, a
state/province, country, etc).
- Taboo Topics: Movie Predictions/Recommendation System; YouTube Data Analysis, Kickstarter
success prediction/analysis,prediction of what makes a song popular on Spotify
Final Project: Objectives
● Identify the problems and goals of a real situation and dataset.
● Choose an appropriate approach for formalizing and testing the problems and goals, and be able to articulate the
reasoning for that selection.
● Implement your analysis choices on the dataset(s).
● Interpret the results of the analyses.
● Contextualize those results within a greater scientific and social context, acknowledging and addressing any
potential issues related to privacy and ethics.
● Work effectively to manage a project as part of a team.
Upcoming Project Components
Project Planning Survey (1%) - 1 submission per group (due Fri Week 2)

Project Review (5%) - Before Mon of week 3, your group will be assigned a previous COGS 108 project to
review; A google Form will be released to guide your thinking/discussion about and review of what a
previous COGS 108 group did for their project. (due Fri Week 3)

Project Proposal (8%) - a GitHub repo will be created for your group; ‘submit’ on GitHub (due Fri Week 4)
Project Proposal (8%)

Full project guidelines are here:


https://github.com/COGS108/Projects/blob/master/FinalProject_Guidelines.md

You might also like