Week_06_git
Week_06_git
Introduction to Data
Management
Starting at 1:05
Monday, Oct 7
◎ AtKlass: XXXX
COMP 1238 – Intro to Data
Management
4
Comparing and
versioning text
files
mysite.zip
mysite_new.zip
mysite_final.zip
mysite_final_v2.zip
mysite_final_v2 (1).zip
mysite_final_v2 (2).zip
6
We need to do better than this
mysite.zip
mysite_new.zip
mysite_final.zip
mysite_final_v2.zip
mysite_final_v2 (1).zip
mysite_final_v2 (2).zip
7
Managing versions in other
industries
◎ Where else do we need to strictly manage versions?
◎ Mechanical engineering – blueprints
◎ Legal documents
9
Comparing text files is easier than
technical drawings, a comparison
might look like this
◎ ttt
10
Comparing two files
recipe1.md recipe2.md
1 # Rice with Onions and Miso 1 # Rice with Onions and Miso
2 ## Ingredients: 2 ## Ingredients:
3 * 1 cup of rice 3 for 2 servings
4 * 1 medium onion, chopped 4 * 1 cup of rice
5 * 2 tbsp of miso paste 5 * 1 medium onion, chopped
6 * 2 cups of water 6 * 2 tbsp of miso paste
7 * 1 tbsp of olive oil 7 * 2 cups of water
8 * Salt and pepper to taste 8 * 1 tbsp of vegetable oil
9 * Optional greens for garnish 9 * Salt and pepper to taste
11
Comparison in VSCode
diff recipe1.md recipe2.md
recipe1.md recipe2.md
1 # Rice with Onions and
Miso
diff / patch 1 # Rice with Onions and
Miso
2 2
## Ingredients: ## Ingredients:
3 2a3 3
* 1 cup of rice for 2 servings
4 > for 2 servings 4
* 1 medium onion, chopped * 1 cup of rice
5 7c8 5
* 2 tbsp of miso paste * 1 medium onion, chopped
6 < * 1 tbsp of olive oil 6
* 2 cups of water * 2 tbsp of miso paste
7 --- 7
* 1 tbsp of olive oil * 2 cups of water
8 > * 1 tbsp of vegetable oil 8
* Salt and pepper to taste * 1 tbsp of vegetable oil
9 9d9 9
* Optional greens for * Salt and pepper to taste
< * Optional greens for
garnish
garnish
13
Comparing two smaller files
14
diff left.file right.file
product: Gelato product: Gelato
type: Banana type: Vanilla
amount: 15 amount: 10
unit: kg unit: kg
2,3c2,3
< type: Banana
< amount: 15
---
> type: Vanilla
> amount: 10
15
Sending patches over the email
Was a common practice in the old days, especially for big projects
like the Linux kernel
19
◎ Git was initially developed by Linus Torvalds in
2005 for the Linux Kernel after an unfortunate
conflict related to the previous tool they used
◎ It was initially perceived as overly complex tool
optimized for large open-source projects
◎ But then it gradually took over
20
◎ Open-source software tool ◎ Commercial service in the
installed locally on your cloud. Launched in 2008 as
computer, first released in a startup but currently
2005 owned by Microsoft
◎ Deals with the files on your ◎ Provides a place to store
disk your work in the cloud and
◎ Your local git installation share it with others
communicates with GitHub ◎ Lots of extra functionality on
(or another git server) top - GitHub Pages, GitHub
Projects …
21
◎ Git can be overwhelming
◎ Most git documentation gets
into details very quickly
◎ We will look at the basic
workflow and some terminology
to get you started
22
Using git on your
computer
many options
◎ Command line
◎ Integrated in VSCode & WebStorm
◎ GitHub Desktop client
◎ GitUI –Text mode UI for git
◎…
23
Local and remote repositories
◎ We created a repository on GitHub
◎ But when you “clone” it to your computer, you get a complete
copy including ALL the history with all previous versions of the
files
Typical coding cycle – workflow
◎ The work on a mature software project looks like
1. Get the latest version of the source files
2. Modify them to change something, or fix some issue
3. Save the latest version of the files where our coworkers
can access them
4. Repeat
25
Same cycle with git
When first joining a project, we “clone” the repo and get a local copy of
the repo
user_docs.docx
src
main.rkt
module1.rkt
module2.rkt
module3.rkt
27
Your files in your local git repository
.git
28
Your files in your local git repository
.git
user_docs.docx
src
This mini-filesystem is highly optimized and
main.rkt
pretty complicated. Don’t try to read it directly.
module1.rkt
The job of the git client is to manage this for
module2.rkt you.
29
Your workflow
30
A Commit
src
main.rkt The mini-fs of the repo is “append-
module1.rkt only”. Nothing is ever over-written
module2.rkt commit there, so everything you ever
module3.rkt commit can be recovered.
31
Synchronizing with the server -
push
server, somewhere on the internet,
your local machine
eg. github.com
manu
.git
push
my-
projec docs al.doc
user_
t x
docs.
src docx
main.r
kt
modul
e1.rkt
modul
e2.rkt
modul
e3.rkt
my-
projec
t
docs
manu
al.doc
user_
x
.git pull
docs.
src docx
main.r
kt
modul
e1.rkt
modul
e2.rkt
modul
pull
e3.rkt
my-
projec docs
manu
al.doc
user_
.git
t x
docs.
docx
pull
src main.r
kt
modul
e1.rkt
modul
e2.rkt
modul
pull
e3.rkt
commit
34
The whole picture
a server, somewhere on the
your local machine internet, eg. Github.com
my- manu
al.doc .git sync
projec docs user_
t x
docs.
src docx
main.r
kt
modul
e1.rkt
modul
e2.rkt
modul
sync
e3.rkt
35
Your workflow
sync
commit
sync
36
Your workflow with a partner
sync sync
server
38
Merge conflicts
◎ How git merges automatically
○ Different files changed – no problem
○ Different parts of the same file changed – no problem
◎ Change around the same place of a file = conflict
○ Git notifies you of the conflict and asks to resolve it
manually (we will talk about this later)
39
Tech tools don’t replace the
need for human-to-human
communication
◎ Talk to your coworkers, discuss any plans for large scale
changes
◎ Even if it’s a small change, but one that affects many files, or
parts that someone else was working on lately – talk to them
◎ Live demo …
41
Branching
Branches – why use them
◎ go back in time and create an alternative history line
◎ Release a version
◎ The team continues working on future features
◎ But released version needs occasional urgent bug fixes
Branches – why use them
Development
branch
Production branch
Questions?
45
Links and references
◎ Git Tutorial for Beginners - Git & GitHub Fundamentals In Depth
by @TechWithTim
◎ Other long tutorials
○ Git and GitHub Tutorial for Beginners by Kevin Stratvert
○ Git and GitHub for Beginners - Crash Course
by Gwen Faraday of @faradayacademy
○ GitHub Basics Made Easy: A Fast Beginner's Tutorial!
◎ Git (not really) explained in 100 seconds by Fireship
◎ Download GitHub Desktop
◎ Brief history of Git
◎ GitHub Learning Lab
◎ The Git Book (free online, advanced)
◎ Wikipedia article about patch 46
DRAFTS
47
Git basic workflow
◎ Create or download a repository
○ git pull (or git init)
◎ Track changes
○ git add, git commit
◎ View history
○ git log
◎ Upload changes
○ git push
48
Staging area
52
53
Local and remote repositories
◎ We created a repository on GitHub
◎ But when you “clone” it to your computer, you get a complete
copy including ALL the history with all previous versions of the
files
54
How it’s done in the
parliament?
Example from Bill C-11 (Online Streaming Act)
https://www.parl.ca/documentviewer/en/44-1/bill/C-11/royal-assent
55
Comparing two simple
files
56
Comparing two simple
files
1 # Rice with Onions and Miso <h1>Rice with Onions and Miso</h1>
2 ## Ingredients: <h2>Ingredients for 2 servings:</h2>
57
58
59