SlideShare a Scribd company logo
1
CSE 390
“Lecture 11”
Version control with Git
slides created by Ruth Anderson, images from http://git-scm.com/book/en/
http://www.cs.washington.edu/390a/
2
Basic Intro to Git
• We will:
 Discuss how Git differs from Subversion
 Discuss the basic Git model
 Pull/clone files from a repository on github
 Edit files in your own local Git repo
 Push files to a repo on github
3
Git Resources
• At the command line: (where verb = config, add, commit, etc.)
$ git help <verb>
$ git <verb> --help
$ man git-<verb>
• Free on-line book: http://git-scm.com/book
• Git tutorial: http://schacon.github.com/git/gittutorial.html
• Reference page for Git: http://gitref.org/index.html
• Git website: http://git-scm.com/
• Git for Computer Scientists (http://eagain.net/articles/git-for-
computer-scientists/)
4
Git History
• Came out of Linux development community
• Linus Torvalds, 2005
• Initial goals:
 Speed
 Support for non-linear development (thousands of parallel branches)
 Fully distributed
 Able to handle large projects like Linux efficiently
5
Git uses a distributed model
Centralized Model Distributed Model
(CVS, Subversion, Perforce) (Git, Mercurial)
Result: Many operations are local
6
Git takes snapshots
Subversion
Git
7
Git uses checksums
• In Subversion each modification to the central repo incremented
the version # of the overall repo.
• How will this numbering scheme work when each user has their
own copy of the repo, and commits changes to their local copy of
the repo before pushing to the central server?????
• Instead, Git generates a unique SHA-1 hash – 40 character string
of hex digits, for every commit. Refer to commits by this ID rather
than a version number. Often we only see the first 7 characters:
1677b2d Edited first line of readme
258efa7 Added line to readme
0e52da7 Initial commit
8
A Local Git project has three areas
Unmodified/modified
Files
Staged
Files
Committed
Files
Note: working directory sometimes called the “working tree”, staging area sometimes called the “index”.
9
Git file lifecycle
10
Basic Workflow
Basic Git workflow:
1.Modify files in your working directory.
2.Stage files, adding snapshots of them to your staging area.
3.Do a commit, which takes the files as they are in the staging area
and stores that snapshot permanently to your Git directory.
•Notes:
 If a particular version of a file is in the git directory, it’s considered committed.
 If it’s modified but has been added to the staging area, it is staged.
 If it was changed since it was checked out but has not been staged, it is modified.
11
Aside: So what is github?
• GitHub.com is a site for online storage of Git repositories.
• Many open source projects use it, such as the Linux kernel.
• You can get free space for open source projects or you can pay for
private projects.
Question: Do I have to use github to use Git?
Answer: No!
• you can use Git completely locally for your own purposes, or
• you or someone else could set up a server to share files, or
• you could share a repo with users on the same file system, such as
we did for homework 9 (as long everyone has the needed file
permissions).
12
Get ready to use Git!
1. Set the name and email for Git to use when you commit:
$ git config --global user.name “Bugs Bunny”
$ git config --global user.email bugs@gmail.com
1. You can call git config –list to verify these are set.
2. These will be set globally for all Git projects you work with.
3. You can also set variables on a project-only basis by not using the
--global flag.
4. You can also set the editor that is used for writing commit
messages:
$ git config --global core.editor emacs (it is vim by default)
13
Create a local copy of a repo
2. Two common scenarios: (only do one of these)
a) To clone an already existing repo to your current directory:
$ git clone <url> [local dir name]
This will create a directory named local dir name, containing a working
copy of the files from the repo, and a .git directory (used to hold
the staging area and your actual repo)
b) To create a Git repo in your current directory:
$ git init
This will create a .git directory in your current directory.
Then you can commit files in that directory into the repo:
$ git add file1.java
$ git commit –m “initial project version”
14
Git commands
command description
git clone url [dir] copy a git repository so you can add to it
git add files adds file contents to the staging area
git commit records a snapshot of the staging area
git status view the status of your files in the working
directory and staging area
git diff shows diff of what is staged and what is
modified but unstaged
git help [command] get help info about a particular command
git pull fetch from a remote repo and try to merge
into the current branch
git push push your new branches and data to a
remote repository
others: init, reset, branch, checkout, merge, log, tag
15
Committing files
• The first time we ask a file to be tracked, and every time before we
commit a file we must add it to the staging area:
$ git add README.txt hello.java
This takes a snapshot of these files at this point in time and adds it to
the staging area.
• To move staged changes into the repo we commit:
$ git commit –m “Fixing bug #22”
Note: To unstage a change on a file before you have committed it:
$ git reset HEAD -- filename
Note: To unmodify a modified file:
$ git checkout -- filename
Note: These commands are just acting on your local version of repo.
16
Status and Diff
• To view the status of your files in the working directory and staging
area:
$ git status or
$ git status –s
(-s shows a short one line version similar to svn)
• To see what is modified but unstaged:
$ git diff
• To see staged changes:
$ git diff --cached
17
After editing a file…
[rea@attu1 superstar]$ emacs rea.txt
[rea@attu1 superstar]$ git status
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: rea.txt
#
no changes added to commit (use "git add" and/or "git commit -a")
[rea@attu1 superstar]$ git status -s
M rea.txt  Note: M is in second column = “working tree”
[rea@attu1 superstar]$ git diff  Shows modifications that have not been staged.
diff --git a/rea.txt b/rea.txt
index 66b293d..90b65fd 100644
--- a/rea.txt
+++ b/rea.txt
@@ -1,2 +1,4 @@
Here is rea's file.
+
+One new line added.
[rea@attu1 superstar]$ git diff --cached  Shows nothing, no modifications have been staged yet.
[rea@attu1 superstar]$
18
After adding file to staging area…
[rea@attu1 superstar]$ git add rea.txt
[rea@attu1 superstar]$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: rea.txt
#
[rea@attu1 superstar]$ git status -s
M rea.txt  Note: M is in first column = “staging area”
[rea@attu1 superstar]$ git diff  Note: Shows nothing, no modifications that have not been staged.
[rea@attu1 superstar]$ git diff --cached  Note: Shows staged modifications.
diff --git a/rea.txt b/rea.txt
index 66b293d..90b65fd 100644
--- a/rea.txt
+++ b/rea.txt
@@ -1,2 +1,4 @@
Here is rea's file.
+
+One new line added.
19
Viewing logs
To see a log of all changes in your local repo:
•$ git log or
•$ git log --oneline (to show a shorter version)
1677b2d Edited first line of readme
258efa7 Added line to readme
0e52da7 Initial commit
•git log -5 (to show only the 5 most recent updates, etc.)
Note: changes will be listed by commitID #, (SHA-1 hash)
Note: changes made to the remote repo before the last time you
cloned/pulled from it will also be included here
20
Pulling and Pushing
Good practice:
1.Add and Commit your changes to your local repo
2.Pull from remote repo to get most recent changes (fix conflicts if
necessary, add and commit them to your local repo)
3.Push your changes to the remote repo
To fetch the most recent updates from the remote repo into your
local repo, and put them into your working directory:
$ git pull origin master
To push your changes from your local repo to the remote repo:
$ git push origin master
Notes: origin = an alias for the URL you cloned from
master = the remote branch you are pulling from/pushing to,
(the local branch you are pulling to/pushing from is your current branch)
Note: On attu you will get a Gtk-warning, you can ignore this.
21
Branching
To create a branch called experimental:
•$ git branch experimental
To list all branches: (* shows which one you are currently on)
•$ git branch
To switch to the experimental branch:
•$ git checkout experimental
Later on, changes between the two branches differ, to merge changes
from experimental into the master:
•$ git checkout master
•$ git merge experimental
Note: git log --graph can be useful for showing branches.
Note: These branches are in your local repo!
22
SVN vs. Git
• SVN:
 central repository approach – the main repository is the only “true”
source, only the main repository has the complete file history
 Users check out local copies of the current version
• Git:
 Distributed repository approach – every checkout of the repository is a
full fledged repository, complete with history
 Greater redundancy and speed
 Branching and merging repositories is more heavily used as a result
23
Do This:
1. $ git config --global user.name “Your Name”
2. $ git config --global user.email youremail@whatever.com
3. $ git clone https://github.com/rea2000/santalist.git
Then try:
1. $ git log, $ git log --oneline
2. Create a file named userID.txt (e.g. rea.txt)
3. $ git status, $ git status –s
4. Add the file: $ git add userID.txt
5. $ git status, $ git status –s
6. Commit the file to your local repo:
$ git commit –m “added rea.txt file”
7. $ git status, $ git status –s, $ git log --oneline
*WAIT, DO NOT GO ON TO THE NEXT STEPS UNTIL YOU ARE TOLD TO!!
1. Pull from remote repo: $git pull origin master
2. Push to remote repo: $git push origin master
Ad

More Related Content

What's hot (20)

GIT_In_90_Minutes
GIT_In_90_MinutesGIT_In_90_Minutes
GIT_In_90_Minutes
vimukthirandika
 
The Fundamentals of Git
The Fundamentals of GitThe Fundamentals of Git
The Fundamentals of Git
DivineOmega
 
Git: basic to advanced
Git: basic to advancedGit: basic to advanced
Git: basic to advanced
Yodalee
 
Git introduction
Git introductionGit introduction
Git introduction
satyendrajaladi
 
GIT: Content-addressable filesystem and Version Control System
GIT: Content-addressable filesystem and Version Control SystemGIT: Content-addressable filesystem and Version Control System
GIT: Content-addressable filesystem and Version Control System
Tommaso Visconti
 
Git Tech Talk
Git  Tech TalkGit  Tech Talk
Git Tech Talk
Chris Johnson
 
Understanding about git
Understanding about gitUnderstanding about git
Understanding about git
Sothearin Ren
 
Git Basic
Git BasicGit Basic
Git Basic
Luke Luo
 
Introduction to Git and GitHub
Introduction to Git and GitHubIntroduction to Git and GitHub
Introduction to Git and GitHub
Bioinformatics and Computational Biosciences Branch
 
Grokking opensource with github
Grokking opensource with githubGrokking opensource with github
Grokking opensource with github
GoogleDeveloperStude4
 
Version control system
Version control systemVersion control system
Version control system
Andrew Liu
 
Introducción a git y GitHub
Introducción a git y GitHubIntroducción a git y GitHub
Introducción a git y GitHub
Lucas Videla
 
Git Basics at Rails Underground
Git Basics at Rails UndergroundGit Basics at Rails Underground
Git Basics at Rails Underground
Ariejan de Vroom
 
Git vs svn
Git vs svnGit vs svn
Git vs svn
Suman Mukherjee
 
Git Basics (Professionals)
 Git Basics (Professionals) Git Basics (Professionals)
Git Basics (Professionals)
bryanbibat
 
Git for the absolute beginners
Git for the absolute beginnersGit for the absolute beginners
Git for the absolute beginners
Gabriele Baldassarre
 
Git - Get Ready To Use It
Git - Get Ready To Use ItGit - Get Ready To Use It
Git - Get Ready To Use It
Daniel Kummer
 
Git Real
Git RealGit Real
Git Real
Gong Haibing
 
Git One Day Training Notes
Git One Day Training NotesGit One Day Training Notes
Git One Day Training Notes
glen_a_smith
 
Git real slides
Git real slidesGit real slides
Git real slides
Lucas Couto
 

Viewers also liked (6)

Dr b.nehru rathod gor banjara culture,tradition,festivals and jath system
Dr b.nehru rathod  gor banjara culture,tradition,festivals and jath systemDr b.nehru rathod  gor banjara culture,tradition,festivals and jath system
Dr b.nehru rathod gor banjara culture,tradition,festivals and jath system
Drbanothnehru Rathod
 
Global Hospitals Patient CD
Global Hospitals Patient CDGlobal Hospitals Patient CD
Global Hospitals Patient CD
logan9900
 
2. el rol de las rp
2. el rol de las rp2. el rol de las rp
2. el rol de las rp
Alicia De La Peña
 
giving_direction
 giving_direction giving_direction
giving_direction
statale
 
ANSWERS
ANSWERSANSWERS
ANSWERS
Mohammed A. Mahmoud
 
Cropped_Enrica Lexie
Cropped_Enrica LexieCropped_Enrica Lexie
Cropped_Enrica Lexie
Shenoy Karun
 
Dr b.nehru rathod gor banjara culture,tradition,festivals and jath system
Dr b.nehru rathod  gor banjara culture,tradition,festivals and jath systemDr b.nehru rathod  gor banjara culture,tradition,festivals and jath system
Dr b.nehru rathod gor banjara culture,tradition,festivals and jath system
Drbanothnehru Rathod
 
Global Hospitals Patient CD
Global Hospitals Patient CDGlobal Hospitals Patient CD
Global Hospitals Patient CD
logan9900
 
giving_direction
 giving_direction giving_direction
giving_direction
statale
 
Cropped_Enrica Lexie
Cropped_Enrica LexieCropped_Enrica Lexie
Cropped_Enrica Lexie
Shenoy Karun
 
Ad

Similar to 390a gitintro 12au (20)

sample.pptx
sample.pptxsample.pptx
sample.pptx
UshaSuray
 
github ppt git ppt on git hub to know ab
github ppt git ppt on git hub to know abgithub ppt git ppt on git hub to know ab
github ppt git ppt on git hub to know ab
infoinnext
 
git.ppt.pdf
git.ppt.pdfgit.ppt.pdf
git.ppt.pdf
Roniel Lopez Alvarez
 
git.ppt.pptx power point presentation got Google internet
git.ppt.pptx power point presentation got Google internetgit.ppt.pptx power point presentation got Google internet
git.ppt.pptx power point presentation got Google internet
rani marri
 
Learning git
Learning gitLearning git
Learning git
Sid Anand
 
簡單介紹git
簡單介紹git簡單介紹git
簡單介紹git
Grace Chien
 
Git walkthrough
Git walkthroughGit walkthrough
Git walkthrough
Bimal Jain
 
GIT.pptx
GIT.pptxGIT.pptx
GIT.pptx
Soumen Debgupta
 
Introduction to Git and Github
Introduction to Git and Github Introduction to Git and Github
Introduction to Git and Github
Max Claus Nunes
 
Git and github introduction
Git and github introductionGit and github introduction
Git and github introduction
John(Qiang) Zhang
 
Git training (basic)
Git training (basic)Git training (basic)
Git training (basic)
Arashdeepkaur16
 
Git training v10
Git training v10Git training v10
Git training v10
Skander Hamza
 
Git and Github workshop GDSC MLRITM
Git and Github  workshop GDSC MLRITMGit and Github  workshop GDSC MLRITM
Git and Github workshop GDSC MLRITM
gdsc13
 
Git is a distributed version control system .
Git is a distributed version control system .Git is a distributed version control system .
Git is a distributed version control system .
HELLOWorld889594
 
Git hub
Git hubGit hub
Git hub
Nitin Goel
 
CSE 390 Lecture 9 - Version Control with GIT
CSE 390 Lecture 9 - Version Control with GITCSE 390 Lecture 9 - Version Control with GIT
CSE 390 Lecture 9 - Version Control with GIT
PouriaQashqai1
 
Git
GitGit
Git
Terry Wang
 
Git 入门与实践
Git 入门与实践Git 入门与实践
Git 入门与实践
Terry Wang
 
Git 入门 与 实践
Git 入门 与 实践Git 入门 与 实践
Git 入门 与 实践
Terry Wang
 
Git 101
Git 101Git 101
Git 101
jayrparro
 
github ppt git ppt on git hub to know ab
github ppt git ppt on git hub to know abgithub ppt git ppt on git hub to know ab
github ppt git ppt on git hub to know ab
infoinnext
 
git.ppt.pptx power point presentation got Google internet
git.ppt.pptx power point presentation got Google internetgit.ppt.pptx power point presentation got Google internet
git.ppt.pptx power point presentation got Google internet
rani marri
 
Learning git
Learning gitLearning git
Learning git
Sid Anand
 
Git walkthrough
Git walkthroughGit walkthrough
Git walkthrough
Bimal Jain
 
Introduction to Git and Github
Introduction to Git and Github Introduction to Git and Github
Introduction to Git and Github
Max Claus Nunes
 
Git and Github workshop GDSC MLRITM
Git and Github  workshop GDSC MLRITMGit and Github  workshop GDSC MLRITM
Git and Github workshop GDSC MLRITM
gdsc13
 
Git is a distributed version control system .
Git is a distributed version control system .Git is a distributed version control system .
Git is a distributed version control system .
HELLOWorld889594
 
CSE 390 Lecture 9 - Version Control with GIT
CSE 390 Lecture 9 - Version Control with GITCSE 390 Lecture 9 - Version Control with GIT
CSE 390 Lecture 9 - Version Control with GIT
PouriaQashqai1
 
Git 入门与实践
Git 入门与实践Git 入门与实践
Git 入门与实践
Terry Wang
 
Git 入门 与 实践
Git 入门 与 实践Git 入门 与 实践
Git 入门 与 实践
Terry Wang
 
Ad

More from Nguyen Van Hung (18)

Su dung linux shell
Su dung linux shellSu dung linux shell
Su dung linux shell
Nguyen Van Hung
 
Cai dat va_cau_hinh_iptables
Cai dat va_cau_hinh_iptablesCai dat va_cau_hinh_iptables
Cai dat va_cau_hinh_iptables
Nguyen Van Hung
 
Git slides
Git slidesGit slides
Git slides
Nguyen Van Hung
 
Introduction to git
Introduction to gitIntroduction to git
Introduction to git
Nguyen Van Hung
 
So sánh asp.net và mvc
So sánh asp.net và mvcSo sánh asp.net và mvc
So sánh asp.net và mvc
Nguyen Van Hung
 
Cong thuc sinh hoc 12 day du nhat
Cong thuc sinh hoc 12 day du nhatCong thuc sinh hoc 12 day du nhat
Cong thuc sinh hoc 12 day du nhat
Nguyen Van Hung
 
Cong thuc sinh hoc 12 day du nhat
Cong thuc sinh hoc 12 day du nhatCong thuc sinh hoc 12 day du nhat
Cong thuc sinh hoc 12 day du nhat
Nguyen Van Hung
 
Asp net mvc3 music store egroups vn
Asp net mvc3 music store   egroups vnAsp net mvc3 music store   egroups vn
Asp net mvc3 music store egroups vn
Nguyen Van Hung
 
Asp.net mvc 3 (c#) (9 tutorials) egroups vn
Asp.net mvc 3 (c#) (9 tutorials)   egroups vnAsp.net mvc 3 (c#) (9 tutorials)   egroups vn
Asp.net mvc 3 (c#) (9 tutorials) egroups vn
Nguyen Van Hung
 
Northwind products
Northwind productsNorthwind products
Northwind products
Nguyen Van Hung
 
Cau truc dl_va_giai_thuat_bai1[1] - copy
Cau truc dl_va_giai_thuat_bai1[1] - copyCau truc dl_va_giai_thuat_bai1[1] - copy
Cau truc dl_va_giai_thuat_bai1[1] - copy
Nguyen Van Hung
 
Thạch quyển và các dạng địa hình
Thạch quyển và các dạng địa hìnhThạch quyển và các dạng địa hình
Thạch quyển và các dạng địa hình
Nguyen Van Hung
 
Bài tập về chuẩn hóa chuỗ1
Bài tập về chuẩn hóa chuỗ1Bài tập về chuẩn hóa chuỗ1
Bài tập về chuẩn hóa chuỗ1
Nguyen Van Hung
 
Khoahoctunhien.net mang1chieu
Khoahoctunhien.net mang1chieuKhoahoctunhien.net mang1chieu
Khoahoctunhien.net mang1chieu
Nguyen Van Hung
 
Doi xung mang mot chieu
Doi xung mang mot chieuDoi xung mang mot chieu
Doi xung mang mot chieu
Nguyen Van Hung
 
De cuong tu tuong hcm khoa iv
De cuong tu tuong hcm  khoa ivDe cuong tu tuong hcm  khoa iv
De cuong tu tuong hcm khoa iv
Nguyen Van Hung
 
Cai dat va_cau_hinh_iptables
Cai dat va_cau_hinh_iptablesCai dat va_cau_hinh_iptables
Cai dat va_cau_hinh_iptables
Nguyen Van Hung
 
So sánh asp.net và mvc
So sánh asp.net và mvcSo sánh asp.net và mvc
So sánh asp.net và mvc
Nguyen Van Hung
 
Cong thuc sinh hoc 12 day du nhat
Cong thuc sinh hoc 12 day du nhatCong thuc sinh hoc 12 day du nhat
Cong thuc sinh hoc 12 day du nhat
Nguyen Van Hung
 
Cong thuc sinh hoc 12 day du nhat
Cong thuc sinh hoc 12 day du nhatCong thuc sinh hoc 12 day du nhat
Cong thuc sinh hoc 12 day du nhat
Nguyen Van Hung
 
Asp net mvc3 music store egroups vn
Asp net mvc3 music store   egroups vnAsp net mvc3 music store   egroups vn
Asp net mvc3 music store egroups vn
Nguyen Van Hung
 
Asp.net mvc 3 (c#) (9 tutorials) egroups vn
Asp.net mvc 3 (c#) (9 tutorials)   egroups vnAsp.net mvc 3 (c#) (9 tutorials)   egroups vn
Asp.net mvc 3 (c#) (9 tutorials) egroups vn
Nguyen Van Hung
 
Cau truc dl_va_giai_thuat_bai1[1] - copy
Cau truc dl_va_giai_thuat_bai1[1] - copyCau truc dl_va_giai_thuat_bai1[1] - copy
Cau truc dl_va_giai_thuat_bai1[1] - copy
Nguyen Van Hung
 
Thạch quyển và các dạng địa hình
Thạch quyển và các dạng địa hìnhThạch quyển và các dạng địa hình
Thạch quyển và các dạng địa hình
Nguyen Van Hung
 
Bài tập về chuẩn hóa chuỗ1
Bài tập về chuẩn hóa chuỗ1Bài tập về chuẩn hóa chuỗ1
Bài tập về chuẩn hóa chuỗ1
Nguyen Van Hung
 
Khoahoctunhien.net mang1chieu
Khoahoctunhien.net mang1chieuKhoahoctunhien.net mang1chieu
Khoahoctunhien.net mang1chieu
Nguyen Van Hung
 
De cuong tu tuong hcm khoa iv
De cuong tu tuong hcm  khoa ivDe cuong tu tuong hcm  khoa iv
De cuong tu tuong hcm khoa iv
Nguyen Van Hung
 

Recently uploaded (20)

SPRING FESTIVITIES - UK AND USA -
SPRING FESTIVITIES - UK AND USA            -SPRING FESTIVITIES - UK AND USA            -
SPRING FESTIVITIES - UK AND USA -
Colégio Santa Teresinha
 
Quality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdfQuality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdf
Dr. Bindiya Chauhan
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
One Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learningOne Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learning
momer9505
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Library Association of Ireland
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
Unit 5: Dividend Decisions and its theories
Unit 5: Dividend Decisions and its theoriesUnit 5: Dividend Decisions and its theories
Unit 5: Dividend Decisions and its theories
bharath321164
 
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Celine George
 
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam SuccessUltimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Mark Soia
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
Diabetic neuropathy peripheral autonomic
Diabetic neuropathy peripheral autonomicDiabetic neuropathy peripheral autonomic
Diabetic neuropathy peripheral autonomic
Pankaj Patawari
 
How to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 WebsiteHow to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 Website
Celine George
 
Envenomation---Clinical Toxicology. pptx
Envenomation---Clinical Toxicology. pptxEnvenomation---Clinical Toxicology. pptx
Envenomation---Clinical Toxicology. pptx
rekhapositivity
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-26-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 4-26-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 4-26-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-26-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
Operations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdfOperations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdf
Arab Academy for Science, Technology and Maritime Transport
 
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Library Association of Ireland
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 AccountingHow to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
Celine George
 
Quality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdfQuality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdf
Dr. Bindiya Chauhan
 
One Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learningOne Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learning
momer9505
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Library Association of Ireland
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
Unit 5: Dividend Decisions and its theories
Unit 5: Dividend Decisions and its theoriesUnit 5: Dividend Decisions and its theories
Unit 5: Dividend Decisions and its theories
bharath321164
 
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Celine George
 
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam SuccessUltimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Mark Soia
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
Diabetic neuropathy peripheral autonomic
Diabetic neuropathy peripheral autonomicDiabetic neuropathy peripheral autonomic
Diabetic neuropathy peripheral autonomic
Pankaj Patawari
 
How to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 WebsiteHow to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 Website
Celine George
 
Envenomation---Clinical Toxicology. pptx
Envenomation---Clinical Toxicology. pptxEnvenomation---Clinical Toxicology. pptx
Envenomation---Clinical Toxicology. pptx
rekhapositivity
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Library Association of Ireland
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 AccountingHow to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
Celine George
 

390a gitintro 12au

  • 1. 1 CSE 390 “Lecture 11” Version control with Git slides created by Ruth Anderson, images from http://git-scm.com/book/en/ http://www.cs.washington.edu/390a/
  • 2. 2 Basic Intro to Git • We will:  Discuss how Git differs from Subversion  Discuss the basic Git model  Pull/clone files from a repository on github  Edit files in your own local Git repo  Push files to a repo on github
  • 3. 3 Git Resources • At the command line: (where verb = config, add, commit, etc.) $ git help <verb> $ git <verb> --help $ man git-<verb> • Free on-line book: http://git-scm.com/book • Git tutorial: http://schacon.github.com/git/gittutorial.html • Reference page for Git: http://gitref.org/index.html • Git website: http://git-scm.com/ • Git for Computer Scientists (http://eagain.net/articles/git-for- computer-scientists/)
  • 4. 4 Git History • Came out of Linux development community • Linus Torvalds, 2005 • Initial goals:  Speed  Support for non-linear development (thousands of parallel branches)  Fully distributed  Able to handle large projects like Linux efficiently
  • 5. 5 Git uses a distributed model Centralized Model Distributed Model (CVS, Subversion, Perforce) (Git, Mercurial) Result: Many operations are local
  • 7. 7 Git uses checksums • In Subversion each modification to the central repo incremented the version # of the overall repo. • How will this numbering scheme work when each user has their own copy of the repo, and commits changes to their local copy of the repo before pushing to the central server????? • Instead, Git generates a unique SHA-1 hash – 40 character string of hex digits, for every commit. Refer to commits by this ID rather than a version number. Often we only see the first 7 characters: 1677b2d Edited first line of readme 258efa7 Added line to readme 0e52da7 Initial commit
  • 8. 8 A Local Git project has three areas Unmodified/modified Files Staged Files Committed Files Note: working directory sometimes called the “working tree”, staging area sometimes called the “index”.
  • 10. 10 Basic Workflow Basic Git workflow: 1.Modify files in your working directory. 2.Stage files, adding snapshots of them to your staging area. 3.Do a commit, which takes the files as they are in the staging area and stores that snapshot permanently to your Git directory. •Notes:  If a particular version of a file is in the git directory, it’s considered committed.  If it’s modified but has been added to the staging area, it is staged.  If it was changed since it was checked out but has not been staged, it is modified.
  • 11. 11 Aside: So what is github? • GitHub.com is a site for online storage of Git repositories. • Many open source projects use it, such as the Linux kernel. • You can get free space for open source projects or you can pay for private projects. Question: Do I have to use github to use Git? Answer: No! • you can use Git completely locally for your own purposes, or • you or someone else could set up a server to share files, or • you could share a repo with users on the same file system, such as we did for homework 9 (as long everyone has the needed file permissions).
  • 12. 12 Get ready to use Git! 1. Set the name and email for Git to use when you commit: $ git config --global user.name “Bugs Bunny” $ git config --global user.email [email protected] 1. You can call git config –list to verify these are set. 2. These will be set globally for all Git projects you work with. 3. You can also set variables on a project-only basis by not using the --global flag. 4. You can also set the editor that is used for writing commit messages: $ git config --global core.editor emacs (it is vim by default)
  • 13. 13 Create a local copy of a repo 2. Two common scenarios: (only do one of these) a) To clone an already existing repo to your current directory: $ git clone <url> [local dir name] This will create a directory named local dir name, containing a working copy of the files from the repo, and a .git directory (used to hold the staging area and your actual repo) b) To create a Git repo in your current directory: $ git init This will create a .git directory in your current directory. Then you can commit files in that directory into the repo: $ git add file1.java $ git commit –m “initial project version”
  • 14. 14 Git commands command description git clone url [dir] copy a git repository so you can add to it git add files adds file contents to the staging area git commit records a snapshot of the staging area git status view the status of your files in the working directory and staging area git diff shows diff of what is staged and what is modified but unstaged git help [command] get help info about a particular command git pull fetch from a remote repo and try to merge into the current branch git push push your new branches and data to a remote repository others: init, reset, branch, checkout, merge, log, tag
  • 15. 15 Committing files • The first time we ask a file to be tracked, and every time before we commit a file we must add it to the staging area: $ git add README.txt hello.java This takes a snapshot of these files at this point in time and adds it to the staging area. • To move staged changes into the repo we commit: $ git commit –m “Fixing bug #22” Note: To unstage a change on a file before you have committed it: $ git reset HEAD -- filename Note: To unmodify a modified file: $ git checkout -- filename Note: These commands are just acting on your local version of repo.
  • 16. 16 Status and Diff • To view the status of your files in the working directory and staging area: $ git status or $ git status –s (-s shows a short one line version similar to svn) • To see what is modified but unstaged: $ git diff • To see staged changes: $ git diff --cached
  • 17. 17 After editing a file… [rea@attu1 superstar]$ emacs rea.txt [rea@attu1 superstar]$ git status # On branch master # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: rea.txt # no changes added to commit (use "git add" and/or "git commit -a") [rea@attu1 superstar]$ git status -s M rea.txt  Note: M is in second column = “working tree” [rea@attu1 superstar]$ git diff  Shows modifications that have not been staged. diff --git a/rea.txt b/rea.txt index 66b293d..90b65fd 100644 --- a/rea.txt +++ b/rea.txt @@ -1,2 +1,4 @@ Here is rea's file. + +One new line added. [rea@attu1 superstar]$ git diff --cached  Shows nothing, no modifications have been staged yet. [rea@attu1 superstar]$
  • 18. 18 After adding file to staging area… [rea@attu1 superstar]$ git add rea.txt [rea@attu1 superstar]$ git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: rea.txt # [rea@attu1 superstar]$ git status -s M rea.txt  Note: M is in first column = “staging area” [rea@attu1 superstar]$ git diff  Note: Shows nothing, no modifications that have not been staged. [rea@attu1 superstar]$ git diff --cached  Note: Shows staged modifications. diff --git a/rea.txt b/rea.txt index 66b293d..90b65fd 100644 --- a/rea.txt +++ b/rea.txt @@ -1,2 +1,4 @@ Here is rea's file. + +One new line added.
  • 19. 19 Viewing logs To see a log of all changes in your local repo: •$ git log or •$ git log --oneline (to show a shorter version) 1677b2d Edited first line of readme 258efa7 Added line to readme 0e52da7 Initial commit •git log -5 (to show only the 5 most recent updates, etc.) Note: changes will be listed by commitID #, (SHA-1 hash) Note: changes made to the remote repo before the last time you cloned/pulled from it will also be included here
  • 20. 20 Pulling and Pushing Good practice: 1.Add and Commit your changes to your local repo 2.Pull from remote repo to get most recent changes (fix conflicts if necessary, add and commit them to your local repo) 3.Push your changes to the remote repo To fetch the most recent updates from the remote repo into your local repo, and put them into your working directory: $ git pull origin master To push your changes from your local repo to the remote repo: $ git push origin master Notes: origin = an alias for the URL you cloned from master = the remote branch you are pulling from/pushing to, (the local branch you are pulling to/pushing from is your current branch) Note: On attu you will get a Gtk-warning, you can ignore this.
  • 21. 21 Branching To create a branch called experimental: •$ git branch experimental To list all branches: (* shows which one you are currently on) •$ git branch To switch to the experimental branch: •$ git checkout experimental Later on, changes between the two branches differ, to merge changes from experimental into the master: •$ git checkout master •$ git merge experimental Note: git log --graph can be useful for showing branches. Note: These branches are in your local repo!
  • 22. 22 SVN vs. Git • SVN:  central repository approach – the main repository is the only “true” source, only the main repository has the complete file history  Users check out local copies of the current version • Git:  Distributed repository approach – every checkout of the repository is a full fledged repository, complete with history  Greater redundancy and speed  Branching and merging repositories is more heavily used as a result
  • 23. 23 Do This: 1. $ git config --global user.name “Your Name” 2. $ git config --global user.email [email protected] 3. $ git clone https://github.com/rea2000/santalist.git Then try: 1. $ git log, $ git log --oneline 2. Create a file named userID.txt (e.g. rea.txt) 3. $ git status, $ git status –s 4. Add the file: $ git add userID.txt 5. $ git status, $ git status –s 6. Commit the file to your local repo: $ git commit –m “added rea.txt file” 7. $ git status, $ git status –s, $ git log --oneline *WAIT, DO NOT GO ON TO THE NEXT STEPS UNTIL YOU ARE TOLD TO!! 1. Pull from remote repo: $git pull origin master 2. Push to remote repo: $git push origin master

Editor's Notes

  • #5: Initial goals were to support development of Linux
  • #6: http://git-scm.com/book/en/Getting-Started-About-Version-Control
  • #21: $ git remote -v origin https://github.com/rea2000/santalist.git (fetch) origin https://github.com/rea2000/santalist.git (push)