SlideShare uma empresa Scribd logo
1 de 26
Introduction to
Git Workshop
@rtoal
2013-02-11
Scope
We have only one hour. So this will be just an
introduction. There's no point in overwhelming
people. So...
● We'll see only about 20 basic commands,
leaving all others to a future workshop.
● We're not going anywhere near submodules,
subtree merging, or Git internals.
What is Git?
● A fully distributed VCS (everyone has a
copy of the repo)
● Incredibly fast
● A system that is awesome at branching
● Able to handle huge, huge projects
● So completely unlike CVS and SVN that you
should probably forget everything you
already know about version control if you
want to understand it
Clay Shirky tells you about Git
Watch from 06:15 to 11:00 for now.
(Later watch the whole thing, it's really good!)
Good to know
Git stores snapshots, not diffs
"Everything is local"
Everything is checksummed (SHA-1)
● tamper-proof
● no version numbers
Let's start
Learn by doing:
$ git config --global user.name "Jane Doe"
$ git config --global user.email "jd@example.com"
$ git config --global color.ui auto
$ git config --list
$ cat ~/.gitconfig
$ git config --help
$ git --help
Let's make a project
We have two choices here!
● We can start working locally and import our
work into a new git repo on our box, or
● We can clone an existing repo (for instance,
one that is already sitting at, say,
github.com) to our box.
(We'll do it the first way for now....)
Create a project
$ mkdir hello && cd hello
$ git init
$ ls -la
$ echo 'My first project' > README.md
$ echo 'print("Hello, world")' > hello.py
$ python hello.py
$ git status
$ git add .
$ git status
$ git commit -m "Initial commit"
$ git status
$ git log
Git requires that you explicitly
track files so you don't
accidentally commit things
The "Pay Attention" pic from Pro Git
Repo: metadata +
compressed object
database
Working directory:
a checkout of a
single version of the
project
Staging area (a.k.a.
the Index): says
what will go into the
next commit
How about some changes?
$ vi hello.py # make some edits
$ git status # note it is modified and not staged
$ git add . # stage changes
$ vi hello.py # more fixes
$ git status # heh, modified and unmodified
$ git diff # diff between working files and staged
$ git diff --cached # diff between staged and committed
$ git add . # now all staged
$ git status # all better, see?
$ git commit # brings up an editor to enter message
$ git log # commit log
$ git log -p # commit log with diffs
$ vi hello.py # make another change
$ git commit -a # stage AND commit (cool shortcut!!)
$ git log --oneline # log, one line per commit
Undoing
$ vi hello.py # make a dumb change
$ git status # blech, we don't want it
$ git checkout -- hello.py # blow away the change (CAREFUL!!)
$ git status # see, we're clean again
$ vi hello.py # this time, make a useful change
$ git add . # stage it
$ git status # yep, it's staged
$ git reset HEAD hello.py # unstage
$ git status # just modified, no longer staged
$ git commit -a # okay fine, commit it
$ git revert 5f74082 # "Undo" commit (use your own hash)
$ git log # SEE HOW REVERT WORKS? :-)
TIP: Use a graphical tool for checkouts and resets
Review so far
mv, rm, ls-tree, and gitk
$ git mv hello.py hi.py
$ ls # it renames in the working dir too
$ git status # git knows its a rename
$ vi hi.py # make some changes
$ git commit -a # stage and commit
$ git rm hi.py
$ ls # removes in the working dir too
$ git status # git knows it's a delete
$ git commit -a # commit the delete
$ git log --oneline # what we've done so far
$ git ls-tree HEAD # see what's in your repo
$ gitk # hey it's a cool gui tool!
Branch and merge
$ git branch # hey we're on master
$ git branch -v # a branch SIMPLY points to a commit
$ git branch newstuff # create a new branch
$ git branch -v # it's created but master is active
$ git checkout newstuff # switches to new branch
$ git branch # yay, newstuff is current now
$ vi fancy.js # create a new file on the branch
$ git add . # Can't do commit -a on new files
$ git commit -a
$ git branch -v # see how the branches differ?
$ git checkout master # back to master
$ vi README.md # do a non-conflicting change
$ git branch -v # see how we are doing
$ git merge newstuff # merge newstuff into master
Conflicts
$ git branch -v # on master
$ git checkout newstuff # switch
$ vi fancy.js # make a change
$ git commit -a
$ vi fancy.js # a second change, just for fun
$ git commit -a
$ git checkout master # switch to master
$ vi fancy.js # do a change you know will conflict
$ git commit -a
$ git merge newstuff # CONFLICT
$ vi fancy.js # Repair the conflict
$ git commit -a
$ git log --pretty=raw
$ git log --oneline --decorate --graph --all
$ gitk
More Pictures!
Want to understand exactly what a branch is?
And what the heck is meant by HEAD?
Well, I'm not going to do any better than The
Visual Git Guide, so let's go take a quick look
over there.
Also see Scott Chacon's Screencast on
Branching and Merging. (youtube, 15 min)
The big deal about Git branching
Branching is so cheap and so easy in Git that it
encourages you to branch and merge often.
Firing off a "topic branch" to work on a little
something is easy. You can jump back to the
mainline for a hotfix, take care of that, and then
go back to your topic. So easy.
Let's see it....
Workflow example: topics & hotfixes
(From Section 3.2 of Pro Git)
You've branched to
work on "Issue 53"
You switch back to master,
branch for a hotfix, and
commit the fix
Merge hotfix into
master, then go back
and work on Issue 53
some more Merge Issue 53
into master
1 2
3
4
Another way to "merge"
You can also bring in work from other branches
by cherry-picking and rebasing.
● Cherry picking copies a commit from another
branch by replaying it on the current branch
● Rebasing replays all the commits from
another branch
You get a cleaner, "linear" history with rebase,
but never rebase commits that you have
pushed to a public repository (See ProGit,
section 3.6)
Remotes
Let's share this project on GitHub. First I'll
create the project rtoal/hello there (you will call
it something else of course), then...
$ git remote add origin git@github.com:rtoal/hello.git
$ git remote
$ git remote -v
$ git push -u origin master
"-u" lets us track the remote. From then on we can just
say "git push"
● origin is the remote name
● master is the ref both locally and on
the remote (short for master:master)
Another user
Now open another window to simulate another
user...
$ git clone git@github.com:rtoal/hello.git
$ cd hello
$ vi fancy.js # Make a change
$ git add . # Can't use commit -a
$ git commit
$ git log -v
$ git log --decorate --oneline # So much better!
$ git push # CHECK GITHUB PAGE NOW
$ git log --decorate --oneline # Observe changes after push
Merge conflict from a remote
Go back to the first window. Now...
$ vi fancy.js # Make a conflicting change
$ git commit -a
$ git push # REJECTED!!
$ git status # "Ahead of origin/master by 1 commit"
$ git pull # Whoa, a conflict
$ git commit -a # Commit the, yes, it's a merge
$ git log --decorate --oneline --graph -all
$ git push
$ git log --decorate --oneline --graph --all
$ gitk
Wrapping up that example
Go back to the second window. Now...
$ git status
$ git pull
$ git log --decorate --oneline --graph --all
Fetch or pull?
git pull does some magic: it fetches objects
from the remote into your local repo then
merges them. You'll see your working directory
change.
git fetch just does the fetch part.
See Mark Longair's discussion of why you
should (probably) fetch and merge explicitly,
instead of pulling.
Some good resources
● Official Docs
● Tutorial
● Manual
● Book
● A few git tips you didn't know about
● Visual Guide
● Another Introduction
● Git Reference
Kthxbye
Hopefully, you now feel acquainted with Git,
and are ready to use it with confidence.
Even though we only covered the basics.
NEXT TIME(S):
● Stashing
● Submodules
● Subtree merging
● Rewriting history
● Git internals
● Hosting your own shared Git repository
● More case studies
● GitHub fun -- Forking, GUI tools, etc.

Mais conteúdo relacionado

Mais procurados

Juliette Reinders Folmer - Promote your open source project with GitHub Pages...
Juliette Reinders Folmer - Promote your open source project with GitHub Pages...Juliette Reinders Folmer - Promote your open source project with GitHub Pages...
Juliette Reinders Folmer - Promote your open source project with GitHub Pages...Codemotion
 
Git: Why And How to
Git: Why And How toGit: Why And How to
Git: Why And How tolanhuonga3
 
Introduction To Git Workshop
Introduction To Git WorkshopIntroduction To Git Workshop
Introduction To Git Workshopthemystic_ca
 
Collaborative Development: The Only CD That Matters - Brent Beer - Codemotion...
Collaborative Development: The Only CD That Matters - Brent Beer - Codemotion...Collaborative Development: The Only CD That Matters - Brent Beer - Codemotion...
Collaborative Development: The Only CD That Matters - Brent Beer - Codemotion...Codemotion
 
Version control, you git
Version control, you gitVersion control, you git
Version control, you gitMayur Patil
 
Git 101 Workshop
Git 101 WorkshopGit 101 Workshop
Git 101 WorkshopJoy Seng
 
Git cheat-sheets
Git cheat-sheetsGit cheat-sheets
Git cheat-sheetsozone777
 
Git - the stupid content tracker
Git - the stupid content trackerGit - the stupid content tracker
Git - the stupid content trackerEric Johnson
 
git入門取得編
git入門取得編git入門取得編
git入門取得編yuzu
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to GitRick Umali
 
Git branching model_for_tap_team
Git branching model_for_tap_teamGit branching model_for_tap_team
Git branching model_for_tap_teamGrzegorz Wilczynski
 
Getting Started with Git
Getting Started with GitGetting Started with Git
Getting Started with GitRick Umali
 
Nge-GIT (Belajar Git Bareng)
Nge-GIT (Belajar Git Bareng)Nge-GIT (Belajar Git Bareng)
Nge-GIT (Belajar Git Bareng)Mizan Riqzia
 

Mais procurados (20)

Juliette Reinders Folmer - Promote your open source project with GitHub Pages...
Juliette Reinders Folmer - Promote your open source project with GitHub Pages...Juliette Reinders Folmer - Promote your open source project with GitHub Pages...
Juliette Reinders Folmer - Promote your open source project with GitHub Pages...
 
Git: Why And How to
Git: Why And How toGit: Why And How to
Git: Why And How to
 
Git essentials
Git essentialsGit essentials
Git essentials
 
Introduction To Git Workshop
Introduction To Git WorkshopIntroduction To Git Workshop
Introduction To Git Workshop
 
Git Real
Git RealGit Real
Git Real
 
Collaborative Development: The Only CD That Matters - Brent Beer - Codemotion...
Collaborative Development: The Only CD That Matters - Brent Beer - Codemotion...Collaborative Development: The Only CD That Matters - Brent Beer - Codemotion...
Collaborative Development: The Only CD That Matters - Brent Beer - Codemotion...
 
Version control, you git
Version control, you gitVersion control, you git
Version control, you git
 
Git 101 Workshop
Git 101 WorkshopGit 101 Workshop
Git 101 Workshop
 
Git github
Git githubGit github
Git github
 
How to use git without rage
How to use git without rageHow to use git without rage
How to use git without rage
 
Git cheat-sheets
Git cheat-sheetsGit cheat-sheets
Git cheat-sheets
 
Git - the stupid content tracker
Git - the stupid content trackerGit - the stupid content tracker
Git - the stupid content tracker
 
Git presentation
Git presentationGit presentation
Git presentation
 
git入門取得編
git入門取得編git入門取得編
git入門取得編
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
 
Git branching model_for_tap_team
Git branching model_for_tap_teamGit branching model_for_tap_team
Git branching model_for_tap_team
 
Git basics
Git basicsGit basics
Git basics
 
Getting Started with Git
Getting Started with GitGetting Started with Git
Getting Started with Git
 
Nge-GIT (Belajar Git Bareng)
Nge-GIT (Belajar Git Bareng)Nge-GIT (Belajar Git Bareng)
Nge-GIT (Belajar Git Bareng)
 
Git for the absolute beginners
Git for the absolute beginnersGit for the absolute beginners
Git for the absolute beginners
 

Destaque

Java best practices
Java best practicesJava best practices
Java best practicesRay Toal
 
Turn Your Feeds Into Marketing Assets
Turn Your Feeds Into Marketing AssetsTurn Your Feeds Into Marketing Assets
Turn Your Feeds Into Marketing AssetsDave Schwartz
 
Learning and Modern Programming Languages
Learning and Modern Programming LanguagesLearning and Modern Programming Languages
Learning and Modern Programming LanguagesRay Toal
 
Php development with Docker
Php development with DockerPhp development with Docker
Php development with DockerMichael Bui
 
Git Workshop : Getting Started
Git Workshop : Getting StartedGit Workshop : Getting Started
Git Workshop : Getting StartedWildan Maulana
 
Docker for Developers - PNWPHP 2016 Workshop
Docker for Developers - PNWPHP 2016 WorkshopDocker for Developers - PNWPHP 2016 Workshop
Docker for Developers - PNWPHP 2016 WorkshopChris Tankersley
 
Docker & PHP - Practical use case
Docker & PHP - Practical use caseDocker & PHP - Practical use case
Docker & PHP - Practical use caserjsmelo
 
2013 Social Admissions Report
 2013 Social Admissions Report   2013 Social Admissions Report
2013 Social Admissions Report Uversity, Inc.
 
Docker for PHP Developers - ZendCon 2016
Docker for PHP Developers - ZendCon 2016Docker for PHP Developers - ZendCon 2016
Docker for PHP Developers - ZendCon 2016Chris Tankersley
 
Information Design Web Planning Mockup
Information Design Web Planning MockupInformation Design Web Planning Mockup
Information Design Web Planning MockupANGELA Smithers
 
NTR Lab - bespoke software development in Russia
NTR Lab - bespoke software development in RussiaNTR Lab - bespoke software development in Russia
NTR Lab - bespoke software development in RussiaOlessya
 
Engine lab software hybrid cloud specialists
Engine lab software hybrid cloud specialistsEngine lab software hybrid cloud specialists
Engine lab software hybrid cloud specialistsJohn Rowan
 
Microservices without Servers
Microservices without ServersMicroservices without Servers
Microservices without ServersDev_Events
 
Computer-free Website Development Demo - WordPressDC Jan 2015
 Computer-free Website Development Demo - WordPressDC Jan 2015 Computer-free Website Development Demo - WordPressDC Jan 2015
Computer-free Website Development Demo - WordPressDC Jan 2015Anthony D. Paul
 
component based softwrae engineering Cbse
component based softwrae engineering Cbsecomponent based softwrae engineering Cbse
component based softwrae engineering CbseSravs Dals
 
The App Evolution
The App Evolution The App Evolution
The App Evolution Dev_Events
 

Destaque (20)

Java best practices
Java best practicesJava best practices
Java best practices
 
Turn Your Feeds Into Marketing Assets
Turn Your Feeds Into Marketing AssetsTurn Your Feeds Into Marketing Assets
Turn Your Feeds Into Marketing Assets
 
Learning and Modern Programming Languages
Learning and Modern Programming LanguagesLearning and Modern Programming Languages
Learning and Modern Programming Languages
 
DataPop Presentation
DataPop PresentationDataPop Presentation
DataPop Presentation
 
Php development with Docker
Php development with DockerPhp development with Docker
Php development with Docker
 
Git Workshop : Getting Started
Git Workshop : Getting StartedGit Workshop : Getting Started
Git Workshop : Getting Started
 
Docker for Developers - PNWPHP 2016 Workshop
Docker for Developers - PNWPHP 2016 WorkshopDocker for Developers - PNWPHP 2016 Workshop
Docker for Developers - PNWPHP 2016 Workshop
 
Docker & PHP - Practical use case
Docker & PHP - Practical use caseDocker & PHP - Practical use case
Docker & PHP - Practical use case
 
2013 Social Admissions Report
 2013 Social Admissions Report   2013 Social Admissions Report
2013 Social Admissions Report
 
Docker for PHP Developers - ZendCon 2016
Docker for PHP Developers - ZendCon 2016Docker for PHP Developers - ZendCon 2016
Docker for PHP Developers - ZendCon 2016
 
Information Design Web Planning Mockup
Information Design Web Planning MockupInformation Design Web Planning Mockup
Information Design Web Planning Mockup
 
MockupBuilder
MockupBuilderMockupBuilder
MockupBuilder
 
NTR Lab - bespoke software development in Russia
NTR Lab - bespoke software development in RussiaNTR Lab - bespoke software development in Russia
NTR Lab - bespoke software development in Russia
 
Especialidade de inclusão 5
Especialidade de inclusão 5Especialidade de inclusão 5
Especialidade de inclusão 5
 
Spm file33
Spm file33Spm file33
Spm file33
 
Engine lab software hybrid cloud specialists
Engine lab software hybrid cloud specialistsEngine lab software hybrid cloud specialists
Engine lab software hybrid cloud specialists
 
Microservices without Servers
Microservices without ServersMicroservices without Servers
Microservices without Servers
 
Computer-free Website Development Demo - WordPressDC Jan 2015
 Computer-free Website Development Demo - WordPressDC Jan 2015 Computer-free Website Development Demo - WordPressDC Jan 2015
Computer-free Website Development Demo - WordPressDC Jan 2015
 
component based softwrae engineering Cbse
component based softwrae engineering Cbsecomponent based softwrae engineering Cbse
component based softwrae engineering Cbse
 
The App Evolution
The App Evolution The App Evolution
The App Evolution
 

Semelhante a Git workshop

Git Started With Git
Git Started With GitGit Started With Git
Git Started With GitNick Quaranto
 
Introduction to Git for Artists
Introduction to Git for ArtistsIntroduction to Git for Artists
Introduction to Git for ArtistsDavid Newbury
 
Matt Gauger - Git & Github web414 December 2010
Matt Gauger - Git & Github web414 December 2010Matt Gauger - Git & Github web414 December 2010
Matt Gauger - Git & Github web414 December 2010Matt Gauger
 
Git - Get Ready To Use It
Git - Get Ready To Use ItGit - Get Ready To Use It
Git - Get Ready To Use ItDaniel Kummer
 
Nicola Iarocci - Git stories from the front line - Codemotion Milan 2017
Nicola Iarocci - Git stories from the front line - Codemotion Milan 2017Nicola Iarocci - Git stories from the front line - Codemotion Milan 2017
Nicola Iarocci - Git stories from the front line - Codemotion Milan 2017Codemotion
 
Git lord | A brief intro about git commands in Star Wars theme
Git lord | A brief intro about git commands in Star Wars themeGit lord | A brief intro about git commands in Star Wars theme
Git lord | A brief intro about git commands in Star Wars themeAkarsh Satija
 
Git in pills : git stash
Git in pills : git stashGit in pills : git stash
Git in pills : git stashFederico Panini
 
devops-complete-notes-2.pdf
devops-complete-notes-2.pdfdevops-complete-notes-2.pdf
devops-complete-notes-2.pdfRobinRohit2
 
Getting some Git
Getting some GitGetting some Git
Getting some GitBADR
 

Semelhante a Git workshop (20)

Git Started With Git
Git Started With GitGit Started With Git
Git Started With Git
 
Working with Git
Working with GitWorking with Git
Working with Git
 
Wokshop de Git
Wokshop de Git Wokshop de Git
Wokshop de Git
 
Introduction to Git for Artists
Introduction to Git for ArtistsIntroduction to Git for Artists
Introduction to Git for Artists
 
Git 201
Git 201Git 201
Git 201
 
Loading...git
Loading...gitLoading...git
Loading...git
 
git session --interactive
git session --interactivegit session --interactive
git session --interactive
 
Matt Gauger - Git & Github web414 December 2010
Matt Gauger - Git & Github web414 December 2010Matt Gauger - Git & Github web414 December 2010
Matt Gauger - Git & Github web414 December 2010
 
GIT Basics
GIT BasicsGIT Basics
GIT Basics
 
Git tips
Git tipsGit tips
Git tips
 
Introduction to Git and Github
Introduction to Git and GithubIntroduction to Git and Github
Introduction to Git and Github
 
Git Tech Talk
Git  Tech TalkGit  Tech Talk
Git Tech Talk
 
Git - Get Ready To Use It
Git - Get Ready To Use ItGit - Get Ready To Use It
Git - Get Ready To Use It
 
Gittalk
GittalkGittalk
Gittalk
 
Nicola Iarocci - Git stories from the front line - Codemotion Milan 2017
Nicola Iarocci - Git stories from the front line - Codemotion Milan 2017Nicola Iarocci - Git stories from the front line - Codemotion Milan 2017
Nicola Iarocci - Git stories from the front line - Codemotion Milan 2017
 
Git lord | A brief intro about git commands in Star Wars theme
Git lord | A brief intro about git commands in Star Wars themeGit lord | A brief intro about git commands in Star Wars theme
Git lord | A brief intro about git commands in Star Wars theme
 
Git in pills : git stash
Git in pills : git stashGit in pills : git stash
Git in pills : git stash
 
devops-complete-notes-2.pdf
devops-complete-notes-2.pdfdevops-complete-notes-2.pdf
devops-complete-notes-2.pdf
 
Getting some Git
Getting some GitGetting some Git
Getting some Git
 
Git and github 101
Git and github 101Git and github 101
Git and github 101
 

Último

The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 

Último (20)

The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 

Git workshop

  • 2. Scope We have only one hour. So this will be just an introduction. There's no point in overwhelming people. So... ● We'll see only about 20 basic commands, leaving all others to a future workshop. ● We're not going anywhere near submodules, subtree merging, or Git internals.
  • 3. What is Git? ● A fully distributed VCS (everyone has a copy of the repo) ● Incredibly fast ● A system that is awesome at branching ● Able to handle huge, huge projects ● So completely unlike CVS and SVN that you should probably forget everything you already know about version control if you want to understand it
  • 4. Clay Shirky tells you about Git Watch from 06:15 to 11:00 for now. (Later watch the whole thing, it's really good!)
  • 5. Good to know Git stores snapshots, not diffs "Everything is local" Everything is checksummed (SHA-1) ● tamper-proof ● no version numbers
  • 6. Let's start Learn by doing: $ git config --global user.name "Jane Doe" $ git config --global user.email "jd@example.com" $ git config --global color.ui auto $ git config --list $ cat ~/.gitconfig $ git config --help $ git --help
  • 7. Let's make a project We have two choices here! ● We can start working locally and import our work into a new git repo on our box, or ● We can clone an existing repo (for instance, one that is already sitting at, say, github.com) to our box. (We'll do it the first way for now....)
  • 8. Create a project $ mkdir hello && cd hello $ git init $ ls -la $ echo 'My first project' > README.md $ echo 'print("Hello, world")' > hello.py $ python hello.py $ git status $ git add . $ git status $ git commit -m "Initial commit" $ git status $ git log Git requires that you explicitly track files so you don't accidentally commit things
  • 9. The "Pay Attention" pic from Pro Git Repo: metadata + compressed object database Working directory: a checkout of a single version of the project Staging area (a.k.a. the Index): says what will go into the next commit
  • 10. How about some changes? $ vi hello.py # make some edits $ git status # note it is modified and not staged $ git add . # stage changes $ vi hello.py # more fixes $ git status # heh, modified and unmodified $ git diff # diff between working files and staged $ git diff --cached # diff between staged and committed $ git add . # now all staged $ git status # all better, see? $ git commit # brings up an editor to enter message $ git log # commit log $ git log -p # commit log with diffs $ vi hello.py # make another change $ git commit -a # stage AND commit (cool shortcut!!) $ git log --oneline # log, one line per commit
  • 11. Undoing $ vi hello.py # make a dumb change $ git status # blech, we don't want it $ git checkout -- hello.py # blow away the change (CAREFUL!!) $ git status # see, we're clean again $ vi hello.py # this time, make a useful change $ git add . # stage it $ git status # yep, it's staged $ git reset HEAD hello.py # unstage $ git status # just modified, no longer staged $ git commit -a # okay fine, commit it $ git revert 5f74082 # "Undo" commit (use your own hash) $ git log # SEE HOW REVERT WORKS? :-) TIP: Use a graphical tool for checkouts and resets
  • 13. mv, rm, ls-tree, and gitk $ git mv hello.py hi.py $ ls # it renames in the working dir too $ git status # git knows its a rename $ vi hi.py # make some changes $ git commit -a # stage and commit $ git rm hi.py $ ls # removes in the working dir too $ git status # git knows it's a delete $ git commit -a # commit the delete $ git log --oneline # what we've done so far $ git ls-tree HEAD # see what's in your repo $ gitk # hey it's a cool gui tool!
  • 14. Branch and merge $ git branch # hey we're on master $ git branch -v # a branch SIMPLY points to a commit $ git branch newstuff # create a new branch $ git branch -v # it's created but master is active $ git checkout newstuff # switches to new branch $ git branch # yay, newstuff is current now $ vi fancy.js # create a new file on the branch $ git add . # Can't do commit -a on new files $ git commit -a $ git branch -v # see how the branches differ? $ git checkout master # back to master $ vi README.md # do a non-conflicting change $ git branch -v # see how we are doing $ git merge newstuff # merge newstuff into master
  • 15. Conflicts $ git branch -v # on master $ git checkout newstuff # switch $ vi fancy.js # make a change $ git commit -a $ vi fancy.js # a second change, just for fun $ git commit -a $ git checkout master # switch to master $ vi fancy.js # do a change you know will conflict $ git commit -a $ git merge newstuff # CONFLICT $ vi fancy.js # Repair the conflict $ git commit -a $ git log --pretty=raw $ git log --oneline --decorate --graph --all $ gitk
  • 16. More Pictures! Want to understand exactly what a branch is? And what the heck is meant by HEAD? Well, I'm not going to do any better than The Visual Git Guide, so let's go take a quick look over there. Also see Scott Chacon's Screencast on Branching and Merging. (youtube, 15 min)
  • 17. The big deal about Git branching Branching is so cheap and so easy in Git that it encourages you to branch and merge often. Firing off a "topic branch" to work on a little something is easy. You can jump back to the mainline for a hotfix, take care of that, and then go back to your topic. So easy. Let's see it....
  • 18. Workflow example: topics & hotfixes (From Section 3.2 of Pro Git) You've branched to work on "Issue 53" You switch back to master, branch for a hotfix, and commit the fix Merge hotfix into master, then go back and work on Issue 53 some more Merge Issue 53 into master 1 2 3 4
  • 19. Another way to "merge" You can also bring in work from other branches by cherry-picking and rebasing. ● Cherry picking copies a commit from another branch by replaying it on the current branch ● Rebasing replays all the commits from another branch You get a cleaner, "linear" history with rebase, but never rebase commits that you have pushed to a public repository (See ProGit, section 3.6)
  • 20. Remotes Let's share this project on GitHub. First I'll create the project rtoal/hello there (you will call it something else of course), then... $ git remote add origin git@github.com:rtoal/hello.git $ git remote $ git remote -v $ git push -u origin master "-u" lets us track the remote. From then on we can just say "git push" ● origin is the remote name ● master is the ref both locally and on the remote (short for master:master)
  • 21. Another user Now open another window to simulate another user... $ git clone git@github.com:rtoal/hello.git $ cd hello $ vi fancy.js # Make a change $ git add . # Can't use commit -a $ git commit $ git log -v $ git log --decorate --oneline # So much better! $ git push # CHECK GITHUB PAGE NOW $ git log --decorate --oneline # Observe changes after push
  • 22. Merge conflict from a remote Go back to the first window. Now... $ vi fancy.js # Make a conflicting change $ git commit -a $ git push # REJECTED!! $ git status # "Ahead of origin/master by 1 commit" $ git pull # Whoa, a conflict $ git commit -a # Commit the, yes, it's a merge $ git log --decorate --oneline --graph -all $ git push $ git log --decorate --oneline --graph --all $ gitk
  • 23. Wrapping up that example Go back to the second window. Now... $ git status $ git pull $ git log --decorate --oneline --graph --all
  • 24. Fetch or pull? git pull does some magic: it fetches objects from the remote into your local repo then merges them. You'll see your working directory change. git fetch just does the fetch part. See Mark Longair's discussion of why you should (probably) fetch and merge explicitly, instead of pulling.
  • 25. Some good resources ● Official Docs ● Tutorial ● Manual ● Book ● A few git tips you didn't know about ● Visual Guide ● Another Introduction ● Git Reference
  • 26. Kthxbye Hopefully, you now feel acquainted with Git, and are ready to use it with confidence. Even though we only covered the basics. NEXT TIME(S): ● Stashing ● Submodules ● Subtree merging ● Rewriting history ● Git internals ● Hosting your own shared Git repository ● More case studies ● GitHub fun -- Forking, GUI tools, etc.