SlideShare a Scribd company logo
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.

More Related Content

What's hot

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 to
lanhuonga3
 
Git essentials
Git essentialsGit essentials
Git essentials
Otto Kekäläinen
 
Introduction To Git Workshop
Introduction To Git WorkshopIntroduction To Git Workshop
Introduction To Git Workshop
themystic_ca
 
Git Real
Git RealGit Real
Git Real
Gong Haibing
 
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 git
Mayur Patil
 
Git 101 Workshop
Git 101 WorkshopGit 101 Workshop
Git 101 Workshop
Joy Seng
 
Git github
Git githubGit github
Git github
Anurag Deb
 
How to use git without rage
How to use git without rageHow to use git without rage
How to use git without rage
Javier Lafora Rey
 
Git cheat-sheets
Git cheat-sheetsGit cheat-sheets
Git cheat-sheets
ozone777
 
Git - the stupid content tracker
Git - the stupid content trackerGit - the stupid content tracker
Git - the stupid content tracker
Eric Johnson
 
Git presentation
Git presentationGit presentation
Git presentation
Julien Renaux
 
git入門取得編
git入門取得編git入門取得編
git入門取得編
yuzu
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
Rick Umali
 
Git branching model_for_tap_team
Git branching model_for_tap_teamGit branching model_for_tap_team
Git branching model_for_tap_team
Grzegorz Wilczynski
 
Git basics
Git basicsGit basics
Git basics
terencechia88
 
Getting Started with Git
Getting Started with GitGetting Started with Git
Getting Started with Git
Rick Umali
 
Nge-GIT (Belajar Git Bareng)
Nge-GIT (Belajar Git Bareng)Nge-GIT (Belajar Git Bareng)
Nge-GIT (Belajar Git Bareng)
Mizan Riqzia
 
Git for the absolute beginners
Git for the absolute beginnersGit for the absolute beginners
Git for the absolute beginners
Gabriele Baldassarre
 

What's hot (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
 

Viewers also liked

Java best practices
Java best practicesJava best practices
Java best practices
Ray Toal
 
Turn Your Feeds Into Marketing Assets
Turn Your Feeds Into Marketing AssetsTurn Your Feeds Into Marketing Assets
Turn Your Feeds Into Marketing Assets
Dave Schwartz
 
Learning and Modern Programming Languages
Learning and Modern Programming LanguagesLearning and Modern Programming Languages
Learning and Modern Programming Languages
Ray Toal
 
DataPop Presentation
DataPop PresentationDataPop Presentation
DataPop Presentation
Dealmaker Media
 
Php development with Docker
Php development with DockerPhp development with Docker
Php development with Docker
Michael Bui
 
Git Workshop : Getting Started
Git Workshop : Getting StartedGit Workshop : Getting Started
Git Workshop : Getting Started
Wildan Maulana
 
Docker for Developers - PNWPHP 2016 Workshop
Docker for Developers - PNWPHP 2016 WorkshopDocker for Developers - PNWPHP 2016 Workshop
Docker for Developers - PNWPHP 2016 Workshop
Chris Tankersley
 
Docker & PHP - Practical use case
Docker & PHP - Practical use caseDocker & PHP - Practical use case
Docker & PHP - Practical use case
rjsmelo
 
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 2016
Chris Tankersley
 
Information Design Web Planning Mockup
Information Design Web Planning MockupInformation Design Web Planning Mockup
Information Design Web Planning Mockup
ANGELA Smithers
 
MockupBuilder
MockupBuilderMockupBuilder
MockupBuilder
Lviv Startup Club
 
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
Olessya
 
Especialidade de inclusão 5
Especialidade de inclusão 5Especialidade de inclusão 5
Especialidade de inclusão 5
GRUPO ESCOTEIRO JOÃO OSCALINO
 
Spm file33
Spm file33Spm file33
Spm file33
Poonam Singh
 
Engine lab software hybrid cloud specialists
Engine lab software hybrid cloud specialistsEngine lab software hybrid cloud specialists
Engine lab software hybrid cloud specialists
John Rowan
 
Microservices without Servers
Microservices without ServersMicroservices without Servers
Microservices without Servers
Dev_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 2015
Anthony D. Paul
 
component based softwrae engineering Cbse
component based softwrae engineering Cbsecomponent based softwrae engineering Cbse
component based softwrae engineering Cbse
Sravs Dals
 
The App Evolution
The App Evolution The App Evolution
The App Evolution
Dev_Events
 

Viewers also liked (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
 

Similar to Git workshop

Git Started With Git
Git Started With GitGit Started With Git
Git Started With Git
Nick Quaranto
 
Working with Git
Working with GitWorking with Git
Working with Git
Pete Nicholls
 
Wokshop de Git
Wokshop de Git Wokshop de Git
Wokshop de Git
Alberto Leal
 
Introduction to Git for Artists
Introduction to Git for ArtistsIntroduction to Git for Artists
Introduction to Git for Artists
David Newbury
 
Git 201
Git 201Git 201
Loading...git
Loading...gitLoading...git
Loading...git
Rafael García
 
git session --interactive
git session --interactivegit session --interactive
git session --interactive
Marius Colacioiu
 
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
Matt Gauger
 
GIT Basics
GIT BasicsGIT Basics
GIT Basics
Tagged Social
 
Git tips
Git tipsGit tips
Git tips
Arthur Shvetsov
 
Introduction to Git and Github
Introduction to Git and GithubIntroduction to Git and Github
Introduction to Git and Github
Md Atique Ahmed Ziad
 
Git Tech Talk
Git  Tech TalkGit  Tech Talk
Git Tech Talk
Chris Johnson
 
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
 
Gittalk
GittalkGittalk
Gittalk
prtinsley
 
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
Codemotion
 
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
Akarsh Satija
 
Git in pills : git stash
Git in pills : git stashGit in pills : git stash
Git in pills : git stash
Federico Panini
 
devops-complete-notes-2.pdf
devops-complete-notes-2.pdfdevops-complete-notes-2.pdf
devops-complete-notes-2.pdf
RobinRohit2
 
Getting some Git
Getting some GitGetting some Git
Getting some Git
BADR
 
Git and github 101
Git and github 101Git and github 101
Git and github 101
Senthilkumar Gopal
 

Similar to 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
 

Recently uploaded

Harnessing the Power of NLP and Knowledge Graphs for Opioid Research
Harnessing the Power of NLP and Knowledge Graphs for Opioid ResearchHarnessing the Power of NLP and Knowledge Graphs for Opioid Research
Harnessing the Power of NLP and Knowledge Graphs for Opioid Research
Neo4j
 
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
Fwdays
 
GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
Javier Junquera
 
A Deep Dive into ScyllaDB's Architecture
A Deep Dive into ScyllaDB's ArchitectureA Deep Dive into ScyllaDB's Architecture
A Deep Dive into ScyllaDB's Architecture
ScyllaDB
 
PRODUCT LISTING OPTIMIZATION PRESENTATION.pptx
PRODUCT LISTING OPTIMIZATION PRESENTATION.pptxPRODUCT LISTING OPTIMIZATION PRESENTATION.pptx
PRODUCT LISTING OPTIMIZATION PRESENTATION.pptx
christinelarrosa
 
QR Secure: A Hybrid Approach Using Machine Learning and Security Validation F...
QR Secure: A Hybrid Approach Using Machine Learning and Security Validation F...QR Secure: A Hybrid Approach Using Machine Learning and Security Validation F...
QR Secure: A Hybrid Approach Using Machine Learning and Security Validation F...
AlexanderRichford
 
Must Know Postgres Extension for DBA and Developer during Migration
Must Know Postgres Extension for DBA and Developer during MigrationMust Know Postgres Extension for DBA and Developer during Migration
Must Know Postgres Extension for DBA and Developer during Migration
Mydbops
 
Day 2 - Intro to UiPath Studio Fundamentals
Day 2 - Intro to UiPath Studio FundamentalsDay 2 - Intro to UiPath Studio Fundamentals
Day 2 - Intro to UiPath Studio Fundamentals
UiPathCommunity
 
Poznań ACE event - 19.06.2024 Team 24 Wrapup slidedeck
Poznań ACE event - 19.06.2024 Team 24 Wrapup slidedeckPoznań ACE event - 19.06.2024 Team 24 Wrapup slidedeck
Poznań ACE event - 19.06.2024 Team 24 Wrapup slidedeck
FilipTomaszewski5
 
"Scaling RAG Applications to serve millions of users", Kevin Goedecke
"Scaling RAG Applications to serve millions of users",  Kevin Goedecke"Scaling RAG Applications to serve millions of users",  Kevin Goedecke
"Scaling RAG Applications to serve millions of users", Kevin Goedecke
Fwdays
 
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectorsConnector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
DianaGray10
 
Essentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation ParametersEssentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation Parameters
Safe Software
 
Leveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and StandardsLeveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and Standards
Neo4j
 
Christine's Product Research Presentation.pptx
Christine's Product Research Presentation.pptxChristine's Product Research Presentation.pptx
Christine's Product Research Presentation.pptx
christinelarrosa
 
What is an RPA CoE? Session 2 – CoE Roles
What is an RPA CoE?  Session 2 – CoE RolesWhat is an RPA CoE?  Session 2 – CoE Roles
What is an RPA CoE? Session 2 – CoE Roles
DianaGray10
 
Principle of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptxPrinciple of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptx
BibashShahi
 
Introducing BoxLang : A new JVM language for productivity and modularity!
Introducing BoxLang : A new JVM language for productivity and modularity!Introducing BoxLang : A new JVM language for productivity and modularity!
Introducing BoxLang : A new JVM language for productivity and modularity!
Ortus Solutions, Corp
 
Christine's Supplier Sourcing Presentaion.pptx
Christine's Supplier Sourcing Presentaion.pptxChristine's Supplier Sourcing Presentaion.pptx
Christine's Supplier Sourcing Presentaion.pptx
christinelarrosa
 
Session 1 - Intro to Robotic Process Automation.pdf
Session 1 - Intro to Robotic Process Automation.pdfSession 1 - Intro to Robotic Process Automation.pdf
Session 1 - Intro to Robotic Process Automation.pdf
UiPathCommunity
 
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
DanBrown980551
 

Recently uploaded (20)

Harnessing the Power of NLP and Knowledge Graphs for Opioid Research
Harnessing the Power of NLP and Knowledge Graphs for Opioid ResearchHarnessing the Power of NLP and Knowledge Graphs for Opioid Research
Harnessing the Power of NLP and Knowledge Graphs for Opioid Research
 
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
 
GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
 
A Deep Dive into ScyllaDB's Architecture
A Deep Dive into ScyllaDB's ArchitectureA Deep Dive into ScyllaDB's Architecture
A Deep Dive into ScyllaDB's Architecture
 
PRODUCT LISTING OPTIMIZATION PRESENTATION.pptx
PRODUCT LISTING OPTIMIZATION PRESENTATION.pptxPRODUCT LISTING OPTIMIZATION PRESENTATION.pptx
PRODUCT LISTING OPTIMIZATION PRESENTATION.pptx
 
QR Secure: A Hybrid Approach Using Machine Learning and Security Validation F...
QR Secure: A Hybrid Approach Using Machine Learning and Security Validation F...QR Secure: A Hybrid Approach Using Machine Learning and Security Validation F...
QR Secure: A Hybrid Approach Using Machine Learning and Security Validation F...
 
Must Know Postgres Extension for DBA and Developer during Migration
Must Know Postgres Extension for DBA and Developer during MigrationMust Know Postgres Extension for DBA and Developer during Migration
Must Know Postgres Extension for DBA and Developer during Migration
 
Day 2 - Intro to UiPath Studio Fundamentals
Day 2 - Intro to UiPath Studio FundamentalsDay 2 - Intro to UiPath Studio Fundamentals
Day 2 - Intro to UiPath Studio Fundamentals
 
Poznań ACE event - 19.06.2024 Team 24 Wrapup slidedeck
Poznań ACE event - 19.06.2024 Team 24 Wrapup slidedeckPoznań ACE event - 19.06.2024 Team 24 Wrapup slidedeck
Poznań ACE event - 19.06.2024 Team 24 Wrapup slidedeck
 
"Scaling RAG Applications to serve millions of users", Kevin Goedecke
"Scaling RAG Applications to serve millions of users",  Kevin Goedecke"Scaling RAG Applications to serve millions of users",  Kevin Goedecke
"Scaling RAG Applications to serve millions of users", Kevin Goedecke
 
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectorsConnector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
 
Essentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation ParametersEssentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation Parameters
 
Leveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and StandardsLeveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and Standards
 
Christine's Product Research Presentation.pptx
Christine's Product Research Presentation.pptxChristine's Product Research Presentation.pptx
Christine's Product Research Presentation.pptx
 
What is an RPA CoE? Session 2 – CoE Roles
What is an RPA CoE?  Session 2 – CoE RolesWhat is an RPA CoE?  Session 2 – CoE Roles
What is an RPA CoE? Session 2 – CoE Roles
 
Principle of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptxPrinciple of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptx
 
Introducing BoxLang : A new JVM language for productivity and modularity!
Introducing BoxLang : A new JVM language for productivity and modularity!Introducing BoxLang : A new JVM language for productivity and modularity!
Introducing BoxLang : A new JVM language for productivity and modularity!
 
Christine's Supplier Sourcing Presentaion.pptx
Christine's Supplier Sourcing Presentaion.pptxChristine's Supplier Sourcing Presentaion.pptx
Christine's Supplier Sourcing Presentaion.pptx
 
Session 1 - Intro to Robotic Process Automation.pdf
Session 1 - Intro to Robotic Process Automation.pdfSession 1 - Intro to Robotic Process Automation.pdf
Session 1 - Intro to Robotic Process Automation.pdf
 
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
 

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.