SlideShare a Scribd company logo
Lecture: Git introduction
Dr. Igor Steinmacher
e-mail: Igor.Steinmacher@nau.edu
Twitter: @igorsteinmacher
INF502
SOFTWARE DEVELOPMENT
METHODOLOGIES
CODE MANAGEMENT/VERSIONING
• Team development
– Code sharing and versioning…
CODE MANAGEMENT/VERSIONING
3
WE WILL FOCUS ON:
4
WHO OFFERS THIS SERVICE
• Your machine! (?)
5
HOW GIT MANAGES FILES OVER TIME
6
GIT - OVERALL
7
GIT LOCAL FLOW - EXAMPLE
8
Commit Branch Merge
F1 F2 F4 F4+
F3 F4*
GIT LOCAL FLOW - EXAMPLE
9
F1 F2 F4
Server
PC
Init
F1 F2 F4
Init
Clone
Push
Class 2
Class 2
Pull
IT’S HANDS ON TIME
• 2 Moments
• Moment 1:
– Local commands: add, commit, branch, merge, conflicts..
• Moment 2
– Interaction with the remote repo: Push, pull
10
KICKING OFF
• git config --global user.name “Igor Steinmacher”
• git config --global user.email “igor.Steinmacher@nau.edu”
• Create a folder / access this folder
• git init
– This folder is a repo
11
For all repos
HANDS ON
• Create a file
• Check the status of the repo
– git status
• Add the file to the index
– git add <filename>
• Check the status
12
HANDS ON
• Our first commit
– git -a -m “Our first commit!!!”
• -a  all files
• -m  will include a commit message
• Check the last commits
– git log
• Check what has been done in the last commit
– git show
13
HANDS ON
• Let’s!
– Change the file
– git status
– git commit …
– git status
– git log
• And this is the basic flow to put your contributions back to the
repo
– add
– commit
– status
– log
– show
14
LET’S BRANCH IT OUT!
• Listing your branches
– git branch
• Create a branch
– git branch <NEW_BRANCH>
• Use another branch
– git checkout <BRANCH_NAME>
• Latest two in one command
– git checkout –b <NEW_BRANCH>
15
WORKING IN A NEW BRANCH
• git checkout -b branchNew
• <Change one existing file here>
– “Hi, my name is Hugh.”
• git commit -a -m “Introducing myself”
• <Check the content of the file>
• git checkout master
• <Check the content of the file>
– What?!?!
16
UPDATING THE MASTER BRANCH
• Usually we branch out for versions, features, bug fixes…
– Later on merging back to master
• How to merge our recently changed file, then?
– In the master branch:
– git merge <other_branch>
• If everything goes smooth… sweet
17
DEALING WITH SMALL CONFLICTS
• Imagine if you change a file in your branch, and someone else
changed the same file
– CONFLICT!!!!
• Can we still merge it?!?!?
– Let’s see:
• Change branch
• Change file
• Commit
• Back to master
• Change the same file
• Commit
• MERGE!
18
USUALLY… FOR THE EASY ONES
Here comes common text before
the area where the conflict happens
and bla bla bla
<<<<<<< HEAD
This is what was in the
master branch
=======
And this…
was in the other branch
>>>>>>> other branch
More text that was common,
and no conflict happened here
19
EXERCISING IT OUT
• Make a new branch called bugfix
• Checkout the bugfix branch with git checkout bugfix
• Create/change a file and commit
• Go back to master with git checkout
• Change/create a file (different from the previous one) and commit
again
• Merge the branch bugfix into master with git merge
20
REBASING IT ALL!!!
• Another way of combining branches
• We can take a set of commits, and copy them in another branch
• Master and our branch are not sync’ed
– Commit made in master
– Commit made in the branch
• From the branch, we can
– git rebase master
– Now the index of the master is “outdated”  HEAD is pointing to
bugfix last commit
• git log --graph --all
21
MOVING FROM HERE TO THERE
• HEAD is the pointer name for the last checked out commit
• We can “detach” the head by “checking out” a specific commit
– git checkout <commit SHA>
• This is not “safe”
– git checkout <branch>
• To get back
• Moving in the commit tree
– Moving one commit at a time with ^
• git checkout HEAD^
• git checkout master^
– Moving a number of times with ~<num>
• git checkout master~3
22
MOVING FROM HERE TO THERE
• We can move a branch!
– git branch -f <BRANCH> HEAD~3
• We can also revert changes
– git reset HEAD~2
• Move the current branch to HEAD - 2 commits position
• Works LOCAL
• git reflog  see previous commits
• git reset <SHA>  SHA of the commit before the reset for
“unresetting”
– git revert HEAD  To reverse changes to send upstream
23
CHERRY-PICKING
• Use when you don’t want to copy ALL commits from a branch to
another
– We can cherry pick those that are of interest
• git cherry-pick <SHA1> <SHA2> <SHA3>
24
DEALING WITH THE REMOTE REPO
25
CREATE A REPO IN GITHUB
26
CLONING TO A LOCAL REPO
• That’s simple! Cloning means bringing all the history to a local
repo
– git clone https://github.com/<owner>/<repo>
• Testing it out
– git clone https://github.com/NAU-OSS/githandson.git
Cloning into 'githandson'...
warning: You appear to have cloned an empty repository.
27
WORKING IN THIS REPO
• Some different commands to deal with remote repo
– git branch –r
– git pull //pulls everything from the remote repo and updates the local
repo
– git fetch //pulls changes from remote repos, but it doesn't integrate any
of this new data into your working files
– git push
• git push <remoteName> <branchName> //push your local changes
to an online repository (git push origin master)
• git push <remoteName> <localBranchName>:<remoteBranchName>
// This pushes the LOCALBRANCHNAME to your REMOTENAME,
but it is renamed to REMOTEBRANCHNAME.
28
USUAL WORKFLOW
• git clone
– branch out to add your changes locally
– your adds/commits
– pull changes to your local repo
– merge your branch back (LOCALLY)
• Resolve any conflict
– push changes back to the remote repo
29
GITHUB WORKFLOW
• Fork + pull-request
– You usually creates a fork for your repo
• “A fork is a copy of a repository. Forking a repository allows you to
freely experiment with changes without affecting the original project”
– Creating a fork
– Then, you usually clone your fork… work, and send a pull request
against the main repo
30
EXAMPLE
31
Server
PC
Pull
master
master
origin/master
master is a local branch
origin/master is a remote branch (a local copy of the branch named
"master" on the remote named "origin")
origin is a remote
EXAMPLE
32
F2
Server
PC
master
master
origin/master
EXAMPLE
33
Server
PC
Pull
master
master
origin/master
EXAMPLE
34
Server
PC
P
u
s
h
master
master
origin/master
Local is outdated
Push
EXAMPLE
35
Server
PC
master
master
origin/master
Push Solution 1:
Fetch +
Rebase +
Push
EXAMPLE
36
Server
PC
master
master
origin/master
Solution 1:
Fetch +
Rebase +
Push
Fetch
EXAMPLE
37
Server
PC
master
master
origin/master
Solution 1:
Fetch +
Rebase +
Push
EXAMPLE
38
Server
PC
master
master
origin/master
Solution 1:
Fetch +
Rebase +
Push
Push
EXAMPLE
39
Server
PC
master
master
origin/master
Push Solution 2:
Pull +
Push
EXAMPLE
40
Server
PC
master
master
origin/master
Solution 2:
Pull +
Push
Pull
EXAMPLE
41
Server
PC
master
master
origin/master
Solution 2:
Pull +
Push
Push
A PULL REQUEST EXAMPLE
• (GitHub) Fork
• (CLI) Clone (the fork)
• (CLI) Commits
• (CLI) Push
• (GitHub) Send Pull Request
– Follow it
– Revise it
– Update it
• Keep your fork up-to-date
– https://help.github.com/articles/syncing-a-fork/
42

More Related Content

Similar to Git first steps

Beginner's Guide to Version Control with Git
Beginner's Guide to Version Control with GitBeginner's Guide to Version Control with Git
Beginner's Guide to Version Control with Git
Robert Lee-Cann
 
Git basic
Git basicGit basic
Git basic
Emran Ul Hadi
 
Git 101
Git 101Git 101
Git 101
Sachet Mittal
 
sample.pptx
sample.pptxsample.pptx
sample.pptx
UshaSuray
 
Git and Github workshop GDSC MLRITM
Git and Github  workshop GDSC MLRITMGit and Github  workshop GDSC MLRITM
Git and Github workshop GDSC MLRITM
gdsc13
 
The Fundamentals of Git
The Fundamentals of GitThe Fundamentals of Git
The Fundamentals of Git
DivineOmega
 
Demystifying Git
Demystifying GitDemystifying Git
Demystifying Git
Pablo Quiroga
 
Demystifying Git
Demystifying GitDemystifying Git
Demystifying Git
Pablo Quiroga
 
390a gitintro 12au
390a gitintro 12au390a gitintro 12au
390a gitintro 12au
Nguyen Van Hung
 
Git 101 - Crash Course in Version Control using Git
Git 101 - Crash Course in Version Control using GitGit 101 - Crash Course in Version Control using Git
Git 101 - Crash Course in Version Control using Git
Geoff Hoffman
 
Fall18 Git presentation
Fall18 Git presentationFall18 Git presentation
Fall18 Git presentation
JustinTirrell1
 
git and github
git and githubgit and github
git and github
Darren Oakley
 
Git installation and configuration
Git installation and configurationGit installation and configuration
Git installation and configuration
Kishor Kumar
 
Git tips and tricks
Git   tips and tricksGit   tips and tricks
Git tips and tricks
Chris Ballance
 
Git workshop - University of Moratuwa, Department of Computer Science and Eng...
Git workshop - University of Moratuwa, Department of Computer Science and Eng...Git workshop - University of Moratuwa, Department of Computer Science and Eng...
Git workshop - University of Moratuwa, Department of Computer Science and Eng...
WSO2
 
An introduction to Git
An introduction to GitAn introduction to Git
An introduction to Git
Muhil Vannan
 
Git-ing out of your git messes
Git-ing out of  your git messesGit-ing out of  your git messes
Git-ing out of your git messes
Katie Sylor-Miller
 
Source control management
Source control managementSource control management
Source control management
Owen Winkler
 
Introduction to git and githhub with practicals.pptx
Introduction to git and githhub with practicals.pptxIntroduction to git and githhub with practicals.pptx
Introduction to git and githhub with practicals.pptx
Abdul Salam
 
Git session Dropsolid.com
Git session Dropsolid.comGit session Dropsolid.com
Git session Dropsolid.com
dropsolid
 

Similar to Git first steps (20)

Beginner's Guide to Version Control with Git
Beginner's Guide to Version Control with GitBeginner's Guide to Version Control with Git
Beginner's Guide to Version Control with Git
 
Git basic
Git basicGit basic
Git basic
 
Git 101
Git 101Git 101
Git 101
 
sample.pptx
sample.pptxsample.pptx
sample.pptx
 
Git and Github workshop GDSC MLRITM
Git and Github  workshop GDSC MLRITMGit and Github  workshop GDSC MLRITM
Git and Github workshop GDSC MLRITM
 
The Fundamentals of Git
The Fundamentals of GitThe Fundamentals of Git
The Fundamentals of Git
 
Demystifying Git
Demystifying GitDemystifying Git
Demystifying Git
 
Demystifying Git
Demystifying GitDemystifying Git
Demystifying Git
 
390a gitintro 12au
390a gitintro 12au390a gitintro 12au
390a gitintro 12au
 
Git 101 - Crash Course in Version Control using Git
Git 101 - Crash Course in Version Control using GitGit 101 - Crash Course in Version Control using Git
Git 101 - Crash Course in Version Control using Git
 
Fall18 Git presentation
Fall18 Git presentationFall18 Git presentation
Fall18 Git presentation
 
git and github
git and githubgit and github
git and github
 
Git installation and configuration
Git installation and configurationGit installation and configuration
Git installation and configuration
 
Git tips and tricks
Git   tips and tricksGit   tips and tricks
Git tips and tricks
 
Git workshop - University of Moratuwa, Department of Computer Science and Eng...
Git workshop - University of Moratuwa, Department of Computer Science and Eng...Git workshop - University of Moratuwa, Department of Computer Science and Eng...
Git workshop - University of Moratuwa, Department of Computer Science and Eng...
 
An introduction to Git
An introduction to GitAn introduction to Git
An introduction to Git
 
Git-ing out of your git messes
Git-ing out of  your git messesGit-ing out of  your git messes
Git-ing out of your git messes
 
Source control management
Source control managementSource control management
Source control management
 
Introduction to git and githhub with practicals.pptx
Introduction to git and githhub with practicals.pptxIntroduction to git and githhub with practicals.pptx
Introduction to git and githhub with practicals.pptx
 
Git session Dropsolid.com
Git session Dropsolid.comGit session Dropsolid.com
Git session Dropsolid.com
 

Recently uploaded

Stack Memory Organization of 8086 Microprocessor
Stack Memory Organization of 8086 MicroprocessorStack Memory Organization of 8086 Microprocessor
Stack Memory Organization of 8086 Microprocessor
JomonJoseph58
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
Standardized tool for Intelligence test.
Standardized tool for Intelligence test.Standardized tool for Intelligence test.
Standardized tool for Intelligence test.
deepaannamalai16
 
HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.
deepaannamalai16
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
haiqairshad
 
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
National Information Standards Organization (NISO)
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
TechSoup
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
Celine George
 
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
EduSkills OECD
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptxRESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
zuzanka
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
History of Stoke Newington
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Denish Jangid
 
math operations ued in python and all used
math operations ued in python and all usedmath operations ued in python and all used
math operations ued in python and all used
ssuser13ffe4
 
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
Nguyen Thanh Tu Collection
 
Bonku-Babus-Friend by Sathyajith Ray (9)
Bonku-Babus-Friend by Sathyajith Ray  (9)Bonku-Babus-Friend by Sathyajith Ray  (9)
Bonku-Babus-Friend by Sathyajith Ray (9)
nitinpv4ai
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
HajraNaeem15
 
Electric Fetus - Record Store Scavenger Hunt
Electric Fetus - Record Store Scavenger HuntElectric Fetus - Record Store Scavenger Hunt
Electric Fetus - Record Store Scavenger Hunt
RamseyBerglund
 
Nutrition Inc FY 2024, 4 - Hour Training
Nutrition Inc FY 2024, 4 - Hour TrainingNutrition Inc FY 2024, 4 - Hour Training
Nutrition Inc FY 2024, 4 - Hour Training
melliereed
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
TechSoup
 

Recently uploaded (20)

Stack Memory Organization of 8086 Microprocessor
Stack Memory Organization of 8086 MicroprocessorStack Memory Organization of 8086 Microprocessor
Stack Memory Organization of 8086 Microprocessor
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
Standardized tool for Intelligence test.
Standardized tool for Intelligence test.Standardized tool for Intelligence test.
Standardized tool for Intelligence test.
 
HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
 
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
 
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptxRESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
 
math operations ued in python and all used
math operations ued in python and all usedmath operations ued in python and all used
math operations ued in python and all used
 
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
 
Bonku-Babus-Friend by Sathyajith Ray (9)
Bonku-Babus-Friend by Sathyajith Ray  (9)Bonku-Babus-Friend by Sathyajith Ray  (9)
Bonku-Babus-Friend by Sathyajith Ray (9)
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
 
Electric Fetus - Record Store Scavenger Hunt
Electric Fetus - Record Store Scavenger HuntElectric Fetus - Record Store Scavenger Hunt
Electric Fetus - Record Store Scavenger Hunt
 
Nutrition Inc FY 2024, 4 - Hour Training
Nutrition Inc FY 2024, 4 - Hour TrainingNutrition Inc FY 2024, 4 - Hour Training
Nutrition Inc FY 2024, 4 - Hour Training
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
 

Git first steps

  • 1. Lecture: Git introduction Dr. Igor Steinmacher e-mail: Igor.Steinmacher@nau.edu Twitter: @igorsteinmacher INF502 SOFTWARE DEVELOPMENT METHODOLOGIES
  • 2. CODE MANAGEMENT/VERSIONING • Team development – Code sharing and versioning…
  • 5. WHO OFFERS THIS SERVICE • Your machine! (?) 5
  • 6. HOW GIT MANAGES FILES OVER TIME 6
  • 8. GIT LOCAL FLOW - EXAMPLE 8 Commit Branch Merge F1 F2 F4 F4+ F3 F4*
  • 9. GIT LOCAL FLOW - EXAMPLE 9 F1 F2 F4 Server PC Init F1 F2 F4 Init Clone Push Class 2 Class 2 Pull
  • 10. IT’S HANDS ON TIME • 2 Moments • Moment 1: – Local commands: add, commit, branch, merge, conflicts.. • Moment 2 – Interaction with the remote repo: Push, pull 10
  • 11. KICKING OFF • git config --global user.name “Igor Steinmacher” • git config --global user.email “igor.Steinmacher@nau.edu” • Create a folder / access this folder • git init – This folder is a repo 11 For all repos
  • 12. HANDS ON • Create a file • Check the status of the repo – git status • Add the file to the index – git add <filename> • Check the status 12
  • 13. HANDS ON • Our first commit – git -a -m “Our first commit!!!” • -a  all files • -m  will include a commit message • Check the last commits – git log • Check what has been done in the last commit – git show 13
  • 14. HANDS ON • Let’s! – Change the file – git status – git commit … – git status – git log • And this is the basic flow to put your contributions back to the repo – add – commit – status – log – show 14
  • 15. LET’S BRANCH IT OUT! • Listing your branches – git branch • Create a branch – git branch <NEW_BRANCH> • Use another branch – git checkout <BRANCH_NAME> • Latest two in one command – git checkout –b <NEW_BRANCH> 15
  • 16. WORKING IN A NEW BRANCH • git checkout -b branchNew • <Change one existing file here> – “Hi, my name is Hugh.” • git commit -a -m “Introducing myself” • <Check the content of the file> • git checkout master • <Check the content of the file> – What?!?! 16
  • 17. UPDATING THE MASTER BRANCH • Usually we branch out for versions, features, bug fixes… – Later on merging back to master • How to merge our recently changed file, then? – In the master branch: – git merge <other_branch> • If everything goes smooth… sweet 17
  • 18. DEALING WITH SMALL CONFLICTS • Imagine if you change a file in your branch, and someone else changed the same file – CONFLICT!!!! • Can we still merge it?!?!? – Let’s see: • Change branch • Change file • Commit • Back to master • Change the same file • Commit • MERGE! 18
  • 19. USUALLY… FOR THE EASY ONES Here comes common text before the area where the conflict happens and bla bla bla <<<<<<< HEAD This is what was in the master branch ======= And this… was in the other branch >>>>>>> other branch More text that was common, and no conflict happened here 19
  • 20. EXERCISING IT OUT • Make a new branch called bugfix • Checkout the bugfix branch with git checkout bugfix • Create/change a file and commit • Go back to master with git checkout • Change/create a file (different from the previous one) and commit again • Merge the branch bugfix into master with git merge 20
  • 21. REBASING IT ALL!!! • Another way of combining branches • We can take a set of commits, and copy them in another branch • Master and our branch are not sync’ed – Commit made in master – Commit made in the branch • From the branch, we can – git rebase master – Now the index of the master is “outdated”  HEAD is pointing to bugfix last commit • git log --graph --all 21
  • 22. MOVING FROM HERE TO THERE • HEAD is the pointer name for the last checked out commit • We can “detach” the head by “checking out” a specific commit – git checkout <commit SHA> • This is not “safe” – git checkout <branch> • To get back • Moving in the commit tree – Moving one commit at a time with ^ • git checkout HEAD^ • git checkout master^ – Moving a number of times with ~<num> • git checkout master~3 22
  • 23. MOVING FROM HERE TO THERE • We can move a branch! – git branch -f <BRANCH> HEAD~3 • We can also revert changes – git reset HEAD~2 • Move the current branch to HEAD - 2 commits position • Works LOCAL • git reflog  see previous commits • git reset <SHA>  SHA of the commit before the reset for “unresetting” – git revert HEAD  To reverse changes to send upstream 23
  • 24. CHERRY-PICKING • Use when you don’t want to copy ALL commits from a branch to another – We can cherry pick those that are of interest • git cherry-pick <SHA1> <SHA2> <SHA3> 24
  • 25. DEALING WITH THE REMOTE REPO 25
  • 26. CREATE A REPO IN GITHUB 26
  • 27. CLONING TO A LOCAL REPO • That’s simple! Cloning means bringing all the history to a local repo – git clone https://github.com/<owner>/<repo> • Testing it out – git clone https://github.com/NAU-OSS/githandson.git Cloning into 'githandson'... warning: You appear to have cloned an empty repository. 27
  • 28. WORKING IN THIS REPO • Some different commands to deal with remote repo – git branch –r – git pull //pulls everything from the remote repo and updates the local repo – git fetch //pulls changes from remote repos, but it doesn't integrate any of this new data into your working files – git push • git push <remoteName> <branchName> //push your local changes to an online repository (git push origin master) • git push <remoteName> <localBranchName>:<remoteBranchName> // This pushes the LOCALBRANCHNAME to your REMOTENAME, but it is renamed to REMOTEBRANCHNAME. 28
  • 29. USUAL WORKFLOW • git clone – branch out to add your changes locally – your adds/commits – pull changes to your local repo – merge your branch back (LOCALLY) • Resolve any conflict – push changes back to the remote repo 29
  • 30. GITHUB WORKFLOW • Fork + pull-request – You usually creates a fork for your repo • “A fork is a copy of a repository. Forking a repository allows you to freely experiment with changes without affecting the original project” – Creating a fork – Then, you usually clone your fork… work, and send a pull request against the main repo 30
  • 31. EXAMPLE 31 Server PC Pull master master origin/master master is a local branch origin/master is a remote branch (a local copy of the branch named "master" on the remote named "origin") origin is a remote
  • 42. A PULL REQUEST EXAMPLE • (GitHub) Fork • (CLI) Clone (the fork) • (CLI) Commits • (CLI) Push • (GitHub) Send Pull Request – Follow it – Revise it – Update it • Keep your fork up-to-date – https://help.github.com/articles/syncing-a-fork/ 42