SlideShare ist ein Scribd-Unternehmen logo
1 von 35
Downloaden Sie, um offline zu lesen
Git in gear:

How to track changes, travel back in time,
and code nicely with others.
Fureigh
@fureigh — info@fureigh.com
NYC Camp
April 10, 2014
Who am I?
Fureigh
Drupal and CiviCRM developer
2014 Code for America Fellow
info@fureigh.com — fureigh on drupal.org, IRC, Twitter, etc.
Who am I?
What are we going to discuss?
• What version control is and why we
care
• Setting up and getting started with
Git
• Fundamental commands
• How to use Git to experiment safely
• How to see who did what when
• Simple daily workflow (public repos)
What are we going to discuss?
• GitHub (github.com) – http://try.github.io
• This is by no means an exhaustive
guide to Git. See “Resources.”
• This will be less fun without a
computer, but you can still learn!
What we’re not doing
What is version control?
(save points for your work.)
!
(not only for code.)
Why use version control?
(tl;dr: to reduce
suffering.)
Why Git in particular?
• Cheap local branching
• Multiple workflows
• Fast
Let’s try it out!
• Linux: Search for ‘git’ or ‘git-core’

sudo yum install git / sudo apt-get install git-core

• Mac:

Download from git-scm.com

Applications -> Utilities -> Terminal

• Windows:

Download from git-scm.com

Start -> Programs -> Git -> Git Bash
Installing Git
10
Introduce yourself to Git
• Tell it your name:

git config --global user.name “Your Name”

• And your email address:

git config --global user.email
“your@email.com”

• And avoid unnecessary hassle:

git config --global core.safecrlf true
• Make a new project directory:

! mkdir myproject

cd myproject
• Tell Git to start paying attention to
your project:

! git init!
• Check what you’ve done.

git status
Starting a new project
• Make a new file:

touch newfile.txt
• Add it:

git add newfile.txt
• And make an initial commit:

! git commit -m “Initial 

commit.”
• See what you’ve done:

git log
Adding and committing
• The smaller your commits, the easier
it’ll be for you to go back and see
what you’ve done.

• …or undo changes that caused
damage.
Commit early and often!
• To edit your last commit message
(for the perfectionists among us):



git commit --amend -m “You see, 

what I really meant to say was 

this.”
Fear of (mis)commitment
• Make a change to newfile.txt.

vi newfile.txt
• See which files have been changed:

git status
• See more precisely what’s changed:

git diff



(specific file, patch creation)
Checking what’s different
• It’s also what we use to make
patches!
• Make another change:

vi newfile.txt
• See what’s changed:

git diff
• Make it into a patch:

git diff newfile.txt > made-

everything-more-awesome.patch
Hey, speaking of diff…
• Your .gitignore file keeps Git from
getting cluttered.

• Create it in the root directory of your
Git repository.
Keep the crud out
• Let’s make a .gitignore file.

touch secret_passwords.txt

vi .gitignore

.secret_passwords.txt



(Note: case-sensitive!)
• What else might we .gitignore?

sites/default/settings.php

*.DS_Store
• git add .gitignore
moar .gitignore
• Make a new branch and switch to it:

git checkout -b 41014-snazzytheme

• View current branches:

git branch

(Asterisk tells you where you are.)

• (If you wanted to switch back to master:)

git checkout master
Using Git to experiment safely
• Make edits.
• Check status.
• Diff to check what’s changed.
• Add files if necessary.
• Commit changes. They’ll go to the
41014-snazzytheme branch, NOT to
master.
Wash, rinse, repeat.
• First, switch back to master:

git checkout master
• You can verify that:

git branch
• Merge the other branch:

git merge snazzytheme

(No squashing!)
• You can see the commit in the log:

git log -1

(git log -s)
Putting it back on master
• Delete the ‘snazzytheme’ branch:

git branch -d snazzytheme

• You can verify that:

git branch
Deleting branches
• If you want to mark a commit as
special:



git tag -a v1.0 -m “Initial launch!”

• Tell me all about that, Git.



git show v1.0
Tagging
25
But wait!
Something’s gone wrong!
!
(let’s say)
26
photo by Amy Strycula (http://www.amystrycula.com) (Amy Strycula's personal archive)
[CC-BY-SA-3.0 (http://creativecommons.org/licenses/by-sa/3.0)], via Wikimedia Commons
• Say you delete a file:

git rm newfile.txt
• J/k! Forget everything since my last
commit!

git reset --hard
• Check that all’s well:

git status
• For individual files:

git checkout yesterday.txt
Turning back (recent) time
• What happened? When do you hypothesize
was last-known-good?

git log

git blame – who did this?
• First 5 characters of each long string are a
commit ID.
• To view changes between second and third
commits:

git diff 22222:33333
• To revert:

git revert HEAD <- reverts most recent

or: git checkout 22222 filename.txt
Disaster recovery
• (git clone)
• git checkout master
• git pull
• git checkout -b issue-branch

Creates and switches you into a branch.
• git status (as you’re going along)
• git add [filename]
• git diff
• git commit -m “Detailed commit message.”
• git checkout master
• git merge issue-branch
• git push; git branch -d issue-branch
Simple daily workflow
http://nakedstartup.com/2010/04/simple-daily-git-workflow/
• Each project (module, theme, etc.) gets its
own repository.
• Who gets commit access? Project
administrator and people to whom they grant
permission.
• If you’re a project creator, follow the steps
on the Version Control tab of your project’s
page.
• That page also lets anyone clone the git repo.
Perfect for making patches.
• drupal.org/documentation/git
Git on drupal.org
• git log —name-only

• git add -p
!
• git merge --squash

• (fun with git config: color diffing and more)
Gittin’ fancy
• git-scm.com
• Drupal-specific: drupal.org/documentation/
git

Includes GUI recommendations.
• gitready.com – great for quick answers
• gitimmersion.com – beautiful
• openhatch.org/missions/git – practice!
• try.github.com
Resources
• nyccamp.org/sprint-mentor-sign-up
Thanks!
Now come help at Sunday’s sprint!
Fureigh
fureigh.com
info@fureigh.com
@fureigh
Thanks!

Weitere ähnliche Inhalte

Was ist angesagt?

Git in the Enterprise: How to succeed at DevOps using Git and a monorepo
Git in the Enterprise: How to succeed at DevOps using Git and a monorepoGit in the Enterprise: How to succeed at DevOps using Git and a monorepo
Git in the Enterprise: How to succeed at DevOps using Git and a monorepoGina Bustos
 
Git and GitGHub Basics
Git and GitGHub BasicsGit and GitGHub Basics
Git and GitGHub BasicsAswin Barath
 
Writing Commits for You, Your Friends, and Your Future Self
Writing Commits for You, Your Friends, and Your Future SelfWriting Commits for You, Your Friends, and Your Future Self
Writing Commits for You, Your Friends, and Your Future SelfAll Things Open
 
WTF is GitOps and Why You Should Care?
WTF is GitOps and Why You Should Care?WTF is GitOps and Why You Should Care?
WTF is GitOps and Why You Should Care?Weaveworks
 
Version Control Systems -- Git -- Part I
Version Control Systems -- Git -- Part IVersion Control Systems -- Git -- Part I
Version Control Systems -- Git -- Part ISergey Aganezov
 
You can git
You can gitYou can git
You can gitYu GUAN
 
Version control system and Git
Version control system and GitVersion control system and Git
Version control system and Gitramubonkuri
 
Git: A Getting Started Presentation
Git: A Getting Started PresentationGit: A Getting Started Presentation
Git: A Getting Started PresentationNap Ramirez
 
Github 101 An Adventurer's Guide To Open Source
Github 101   An Adventurer's Guide To Open SourceGithub 101   An Adventurer's Guide To Open Source
Github 101 An Adventurer's Guide To Open SourcePrachitibhukan
 
Web Programming - Git basics
Web Programming - Git basicsWeb Programming - Git basics
Web Programming - Git basicsÖmer Taşkın
 
Git the fast version control system
Git the fast version control systemGit the fast version control system
Git the fast version control systemJeroen Rosenberg
 

Was ist angesagt? (20)

Git in the Enterprise: How to succeed at DevOps using Git and a monorepo
Git in the Enterprise: How to succeed at DevOps using Git and a monorepoGit in the Enterprise: How to succeed at DevOps using Git and a monorepo
Git in the Enterprise: How to succeed at DevOps using Git and a monorepo
 
Git slides
Git slidesGit slides
Git slides
 
Git and GitGHub Basics
Git and GitGHub BasicsGit and GitGHub Basics
Git and GitGHub Basics
 
Intro to Git & GitHub
Intro to Git & GitHubIntro to Git & GitHub
Intro to Git & GitHub
 
Git General
Git GeneralGit General
Git General
 
Writing Commits for You, Your Friends, and Your Future Self
Writing Commits for You, Your Friends, and Your Future SelfWriting Commits for You, Your Friends, and Your Future Self
Writing Commits for You, Your Friends, and Your Future Self
 
Git Tutorial
Git Tutorial Git Tutorial
Git Tutorial
 
WTF is GitOps and Why You Should Care?
WTF is GitOps and Why You Should Care?WTF is GitOps and Why You Should Care?
WTF is GitOps and Why You Should Care?
 
Version Control Systems -- Git -- Part I
Version Control Systems -- Git -- Part IVersion Control Systems -- Git -- Part I
Version Control Systems -- Git -- Part I
 
You can git
You can gitYou can git
You can git
 
SCM Boot Camp
SCM Boot CampSCM Boot Camp
SCM Boot Camp
 
Version control system and Git
Version control system and GitVersion control system and Git
Version control system and Git
 
Git hub
Git hubGit hub
Git hub
 
Git: A Getting Started Presentation
Git: A Getting Started PresentationGit: A Getting Started Presentation
Git: A Getting Started Presentation
 
Github 101 An Adventurer's Guide To Open Source
Github 101   An Adventurer's Guide To Open SourceGithub 101   An Adventurer's Guide To Open Source
Github 101 An Adventurer's Guide To Open Source
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
 
Git 01
Git 01Git 01
Git 01
 
Web Programming - Git basics
Web Programming - Git basicsWeb Programming - Git basics
Web Programming - Git basics
 
Git the fast version control system
Git the fast version control systemGit the fast version control system
Git the fast version control system
 
Webinar : SVN to GIT Migration
Webinar : SVN to GIT Migration Webinar : SVN to GIT Migration
Webinar : SVN to GIT Migration
 

Andere mochten auch

Intermediate Git: Workflows for Teams at DrupalCamp LA, 2015
Intermediate Git: Workflows for Teams at DrupalCamp LA, 2015Intermediate Git: Workflows for Teams at DrupalCamp LA, 2015
Intermediate Git: Workflows for Teams at DrupalCamp LA, 2015mwrather
 
Views Style Plugins
Views Style PluginsViews Style Plugins
Views Style Pluginsmwrather
 
A painless git workflow
A painless git workflowA painless git workflow
A painless git workflowrogthefrog
 
How to store large binary files in git repositories
How to store large binary files in git repositoriesHow to store large binary files in git repositories
How to store large binary files in git repositoriesMatt Aunger
 
Version Control & Git
Version Control & GitVersion Control & Git
Version Control & GitCraig Smith
 
What is version control software and why do you need it?
What is version control software and why do you need it?What is version control software and why do you need it?
What is version control software and why do you need it?Leonid Mamchenkov
 
Introduction to Version Control
Introduction to Version ControlIntroduction to Version Control
Introduction to Version ControlJeremy Coates
 
UX, ethnography and possibilities: for Libraries, Museums and Archives
UX, ethnography and possibilities: for Libraries, Museums and ArchivesUX, ethnography and possibilities: for Libraries, Museums and Archives
UX, ethnography and possibilities: for Libraries, Museums and ArchivesNed Potter
 

Andere mochten auch (12)

Intermediate Git: Workflows for Teams at DrupalCamp LA, 2015
Intermediate Git: Workflows for Teams at DrupalCamp LA, 2015Intermediate Git: Workflows for Teams at DrupalCamp LA, 2015
Intermediate Git: Workflows for Teams at DrupalCamp LA, 2015
 
Views Style Plugins
Views Style PluginsViews Style Plugins
Views Style Plugins
 
Git
GitGit
Git
 
Git advanced
Git advancedGit advanced
Git advanced
 
GIT Fundamentals
GIT FundamentalsGIT Fundamentals
GIT Fundamentals
 
Git Hogent
Git HogentGit Hogent
Git Hogent
 
A painless git workflow
A painless git workflowA painless git workflow
A painless git workflow
 
How to store large binary files in git repositories
How to store large binary files in git repositoriesHow to store large binary files in git repositories
How to store large binary files in git repositories
 
Version Control & Git
Version Control & GitVersion Control & Git
Version Control & Git
 
What is version control software and why do you need it?
What is version control software and why do you need it?What is version control software and why do you need it?
What is version control software and why do you need it?
 
Introduction to Version Control
Introduction to Version ControlIntroduction to Version Control
Introduction to Version Control
 
UX, ethnography and possibilities: for Libraries, Museums and Archives
UX, ethnography and possibilities: for Libraries, Museums and ArchivesUX, ethnography and possibilities: for Libraries, Museums and Archives
UX, ethnography and possibilities: for Libraries, Museums and Archives
 

Ähnlich wie Git in gear: How to track changes, travel back in time, and code nicely with others.

Let's Git this Party Started: An Introduction to Git and GitHub
Let's Git this Party Started: An Introduction to Git and GitHubLet's Git this Party Started: An Introduction to Git and GitHub
Let's Git this Party Started: An Introduction to Git and GitHubKim Moir
 
git and github-1.pptx
git and github-1.pptxgit and github-1.pptx
git and github-1.pptxtnscharishma
 
Git installation and configuration
Git installation and configurationGit installation and configuration
Git installation and configurationKishor Kumar
 
Hello git - a soft introduction to git (Talk Slides)
Hello git - a soft introduction to git (Talk Slides) Hello git - a soft introduction to git (Talk Slides)
Hello git - a soft introduction to git (Talk Slides) Amity University Noida
 
The Basics of Open Source Collaboration With Git and GitHub
The Basics of Open Source Collaboration With Git and GitHubThe Basics of Open Source Collaboration With Git and GitHub
The Basics of Open Source Collaboration With Git and GitHubBigBlueHat
 
Learning git
Learning gitLearning git
Learning gitSid Anand
 
Manage Org Changes Using the Force.com Migration Tool and Git
Manage Org Changes Using the Force.com Migration Tool and GitManage Org Changes Using the Force.com Migration Tool and Git
Manage Org Changes Using the Force.com Migration Tool and GitSalesforce Developers
 
11 git version control
11 git version control11 git version control
11 git version controlWasim Alatrash
 
Source Code Management with Git
Source Code Management with GitSource Code Management with Git
Source Code Management with GitThings Lab
 
Beginner's guide to git and github
Beginner's guide to git and github Beginner's guide to git and github
Beginner's guide to git and github SahilSonar4
 
Introduction To Git Workshop
Introduction To Git WorkshopIntroduction To Git Workshop
Introduction To Git Workshopthemystic_ca
 

Ähnlich wie Git in gear: How to track changes, travel back in time, and code nicely with others. (20)

Techoalien git
Techoalien gitTechoalien git
Techoalien git
 
Techoalien git
Techoalien gitTechoalien git
Techoalien git
 
Techoalien git
Techoalien gitTechoalien git
Techoalien git
 
3 Git
3 Git3 Git
3 Git
 
Let's Git this Party Started: An Introduction to Git and GitHub
Let's Git this Party Started: An Introduction to Git and GitHubLet's Git this Party Started: An Introduction to Git and GitHub
Let's Git this Party Started: An Introduction to Git and GitHub
 
git and github-1.pptx
git and github-1.pptxgit and github-1.pptx
git and github-1.pptx
 
Git installation and configuration
Git installation and configurationGit installation and configuration
Git installation and configuration
 
Hello git - a soft introduction to git (Talk Slides)
Hello git - a soft introduction to git (Talk Slides) Hello git - a soft introduction to git (Talk Slides)
Hello git - a soft introduction to git (Talk Slides)
 
The Basics of Open Source Collaboration With Git and GitHub
The Basics of Open Source Collaboration With Git and GitHubThe Basics of Open Source Collaboration With Git and GitHub
The Basics of Open Source Collaboration With Git and GitHub
 
Demo
DemoDemo
Demo
 
Learning git
Learning gitLearning git
Learning git
 
Git presentation
Git presentationGit presentation
Git presentation
 
Manage Org Changes Using the Force.com Migration Tool and Git
Manage Org Changes Using the Force.com Migration Tool and GitManage Org Changes Using the Force.com Migration Tool and Git
Manage Org Changes Using the Force.com Migration Tool and Git
 
git and github
git and githubgit and github
git and github
 
11 git version control
11 git version control11 git version control
11 git version control
 
Source Code Management with Git
Source Code Management with GitSource Code Management with Git
Source Code Management with Git
 
Beginner's guide to git and github
Beginner's guide to git and github Beginner's guide to git and github
Beginner's guide to git and github
 
Git
GitGit
Git
 
Introduction To Git Workshop
Introduction To Git WorkshopIntroduction To Git Workshop
Introduction To Git Workshop
 
Github basics
Github basicsGithub basics
Github basics
 

Kürzlich hochgeladen

08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 

Kürzlich hochgeladen (20)

08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 

Git in gear: How to track changes, travel back in time, and code nicely with others.

  • 1. Git in gear:
 How to track changes, travel back in time, and code nicely with others. Fureigh @fureigh — info@fureigh.com NYC Camp April 10, 2014
  • 2. Who am I? Fureigh Drupal and CiviCRM developer 2014 Code for America Fellow info@fureigh.com — fureigh on drupal.org, IRC, Twitter, etc. Who am I?
  • 3. What are we going to discuss? • What version control is and why we care • Setting up and getting started with Git • Fundamental commands • How to use Git to experiment safely • How to see who did what when • Simple daily workflow (public repos) What are we going to discuss?
  • 4. • GitHub (github.com) – http://try.github.io • This is by no means an exhaustive guide to Git. See “Resources.” • This will be less fun without a computer, but you can still learn! What we’re not doing
  • 5. What is version control? (save points for your work.) ! (not only for code.)
  • 6. Why use version control? (tl;dr: to reduce suffering.)
  • 7. Why Git in particular? • Cheap local branching • Multiple workflows • Fast
  • 9. • Linux: Search for ‘git’ or ‘git-core’
 sudo yum install git / sudo apt-get install git-core
 • Mac:
 Download from git-scm.com
 Applications -> Utilities -> Terminal
 • Windows:
 Download from git-scm.com
 Start -> Programs -> Git -> Git Bash Installing Git
  • 10. 10
  • 11. Introduce yourself to Git • Tell it your name:
 git config --global user.name “Your Name”
 • And your email address:
 git config --global user.email “your@email.com”
 • And avoid unnecessary hassle:
 git config --global core.safecrlf true
  • 12. • Make a new project directory:
 ! mkdir myproject
 cd myproject • Tell Git to start paying attention to your project:
 ! git init! • Check what you’ve done.
 git status Starting a new project
  • 13. • Make a new file:
 touch newfile.txt • Add it:
 git add newfile.txt • And make an initial commit:
 ! git commit -m “Initial 
 commit.” • See what you’ve done:
 git log Adding and committing
  • 14. • The smaller your commits, the easier it’ll be for you to go back and see what you’ve done.
 • …or undo changes that caused damage. Commit early and often!
  • 15. • To edit your last commit message (for the perfectionists among us):
 
 git commit --amend -m “You see, 
 what I really meant to say was 
 this.” Fear of (mis)commitment
  • 16. • Make a change to newfile.txt.
 vi newfile.txt • See which files have been changed:
 git status • See more precisely what’s changed:
 git diff
 
 (specific file, patch creation) Checking what’s different
  • 17. • It’s also what we use to make patches! • Make another change:
 vi newfile.txt • See what’s changed:
 git diff • Make it into a patch:
 git diff newfile.txt > made-
 everything-more-awesome.patch Hey, speaking of diff…
  • 18. • Your .gitignore file keeps Git from getting cluttered.
 • Create it in the root directory of your Git repository. Keep the crud out
  • 19. • Let’s make a .gitignore file.
 touch secret_passwords.txt
 vi .gitignore
 .secret_passwords.txt
 
 (Note: case-sensitive!) • What else might we .gitignore?
 sites/default/settings.php
 *.DS_Store • git add .gitignore moar .gitignore
  • 20. • Make a new branch and switch to it:
 git checkout -b 41014-snazzytheme
 • View current branches:
 git branch
 (Asterisk tells you where you are.)
 • (If you wanted to switch back to master:)
 git checkout master Using Git to experiment safely
  • 21. • Make edits. • Check status. • Diff to check what’s changed. • Add files if necessary. • Commit changes. They’ll go to the 41014-snazzytheme branch, NOT to master. Wash, rinse, repeat.
  • 22. • First, switch back to master:
 git checkout master • You can verify that:
 git branch • Merge the other branch:
 git merge snazzytheme
 (No squashing!) • You can see the commit in the log:
 git log -1
 (git log -s) Putting it back on master
  • 23. • Delete the ‘snazzytheme’ branch:
 git branch -d snazzytheme
 • You can verify that:
 git branch Deleting branches
  • 24. • If you want to mark a commit as special:
 
 git tag -a v1.0 -m “Initial launch!”
 • Tell me all about that, Git.
 
 git show v1.0 Tagging
  • 25. 25 But wait! Something’s gone wrong! ! (let’s say)
  • 26. 26 photo by Amy Strycula (http://www.amystrycula.com) (Amy Strycula's personal archive) [CC-BY-SA-3.0 (http://creativecommons.org/licenses/by-sa/3.0)], via Wikimedia Commons
  • 27. • Say you delete a file:
 git rm newfile.txt • J/k! Forget everything since my last commit!
 git reset --hard • Check that all’s well:
 git status • For individual files:
 git checkout yesterday.txt Turning back (recent) time
  • 28. • What happened? When do you hypothesize was last-known-good?
 git log
 git blame – who did this? • First 5 characters of each long string are a commit ID. • To view changes between second and third commits:
 git diff 22222:33333 • To revert:
 git revert HEAD <- reverts most recent
 or: git checkout 22222 filename.txt Disaster recovery
  • 29. • (git clone) • git checkout master • git pull • git checkout -b issue-branch
 Creates and switches you into a branch. • git status (as you’re going along) • git add [filename] • git diff • git commit -m “Detailed commit message.” • git checkout master • git merge issue-branch • git push; git branch -d issue-branch Simple daily workflow
  • 31. • Each project (module, theme, etc.) gets its own repository. • Who gets commit access? Project administrator and people to whom they grant permission. • If you’re a project creator, follow the steps on the Version Control tab of your project’s page. • That page also lets anyone clone the git repo. Perfect for making patches. • drupal.org/documentation/git Git on drupal.org
  • 32. • git log —name-only
 • git add -p ! • git merge --squash
 • (fun with git config: color diffing and more) Gittin’ fancy
  • 33. • git-scm.com • Drupal-specific: drupal.org/documentation/ git
 Includes GUI recommendations. • gitready.com – great for quick answers • gitimmersion.com – beautiful • openhatch.org/missions/git – practice! • try.github.com Resources