SlideShare uma empresa Scribd logo
1 de 103
Git session

Hannes Tack
Overview
1. What is git?
2. Basic git
3. Workflow
4. Tips and tricks
What is git?
What is git?

Open source distributed version control system
Distributed
• Everything is local
– Fast
– Every clone is a backup
– Work offline
Basic git
Installing Git
• Download from http://gitscm.com/downloads
• Launch the installer
• Or Xcode, homebrew, …
Configuring Git
• $ git config --global user.name 'Hannes Tack‟
• $ git config –global user.email
„hannes@dropsolid.com‟
Clone a repo
Clone a repo
• Clone an existing repo or create a new one:
– $ git clone user@host:repo
.gitignore
.gitignore
• What?
– Makes git ignore files / directories
– Repo specific or global
– Drupal example of a .gitignore file:
http://drupalcode.org/project/drupal.git/blob/HEAD:
/example.gitignore
.gitignore
# Ignore configuration files that may contain sensitive information
*/sites/*/settings*.php
# Ignore paths that contain user-generated content.
*/sites/*files
*/sites/*/private
# Ignore editor specific files
Drupal.sublime-projectcompletions
*.sublime-project
*.sublime-workspace
# Ignore OS specific files
.DS_Store
global .gitignore
• Create any file:
- $vi ~/.gitignore_global
• Add paths to be ignored.
- Example: https://gist.github.com/4321950

• Use as global gitignore file:
Git config –global core.excludesfile
~/.gitignore_global
local .gitignore
• Create a .gitignore file:
- $vi ~/your_project/.gitignore
• Place it anywhere in your repo
• Add paths to be ignored, relative to the location of
the file.
A Basic Workflow
A basic workflow
•
•
•
•
•

Write code
Stage your changes
Review your changes
Commit your changes
Push your changes
A basic workflow
•
•
•
•
•

Write code
Stage your changes
Review your changes
Commit your changes
Push your changes
A basic workflow
A basic workflow
Git diff
• Git diff shows what you‟ve changed
• $ git diff <filename>
A basic workflow
A basic workflow
•
•
•
•
•

Write code
Stage your changes
Review your changes
Commit your changes
Push your changes
A basic workflow
A basic workflow
A basic workflow
A basic workflow
A basic workflow
Git add
A basic workflow
A basic workflow
A basic workflow
A basic workflow
Staged files
• git diff --staged shows the changes that are
staged
• git reset HEAD <filename> removes a file
from “staging”
A basic workflow
•
•
•
•
•

Write code
Stage your changes
Review your changes
Commit your changes
Push your changes
Git commit
A basic workflow
A basic workflow
A basic workflow
Git commit
• Changes are committed to local repo
• Others won‟t see these changes yet
• Commit message is required
• And should look like „Issue #123: describe what
you changed.‟
A basic workflow
•
•
•
•
•

Write code
Stage your changes
Review your changes
Commit your changes
Push your changes
Git push
A basic workflow
A basic workflow
A basic workflow
Merging
A basic workflow
• Remote branch contains commit(s) that are not
present in your local branch.
• Get those commits first by merging, then push your
commits.
A basic workflow
Git pull
A basic workflow
Git push
A basic workflow
Git pull
A basic workflow
Git pull
A basic workflow
Git pull
A basic workflow
Git pull
A basic workflow
Git pull
A basic workflow
Git pull
A basic workflow
Fix code manually
A basic workflow
Fix conflict UI
A basic workflow
Fix conflict UI
A basic workflow
Push merged code
Git log
Git log
- View the latest 10 log messages
- $ git log -n 10
Git log
- Show nicer log:
- $ git log --oneline -n 20
Git log
- Search log messages content:
$ git log --grep=Breadcrumb
Git log
- Search log messages content:
$ git log --grep=Breadcrumb
Git log
- Search commit content:
$ git log -S "Implements hook_views_data" –oneline
Git log
- Show commit content:
$ git show de25c94
Undoing things
Git checkout
Git checkout
Git checkout
• Throw away changes:
$ git checkout index.html
• Restores your working tree to the last version
committed to git.
• Use git checkout to throw away changes that have
not been added and committed.
• Use carefully.
Git checkout
Git reset
Git reset
Git reset
• Keep your code changes, remove file from
the index:
$ git reset HEAD index.html
• Restores your index to the last version
known to git.
Git reset
Git reset --hard
Git reset --hard
• Resets working tree and index to a specific
commit.
• $ git reset --hard 5497461
• Reset a branch to the origin branch:
$ git
reset --hard origin/master
• Use carefully.
Git revert
Git revert
• Undo a specific commit:
$ git revert
5497461
• Creates a new commit that removes the
specified commit.
Git revert
Branching
Branching
- List local branches:
$ git branch
Branching
- List all branches:
$ git branch -a
Branching
- Create a new branch:
$ git branch issue-123
- Switch to that branch:
$ git checkout issue123
- Or create and switch to a branch:
$ git
checkout -b issue-123
- Push branch to origin:
$ git push origin
issue-123
Branching
- Use a remote branch:
$ git checkout -t
origin/issue-11699
Branching
• Delete a local branch that is fully merged:
$
git branch -d branch_name
• Force delete a local branch:
$ git branch -D
branch_name
• Delete a remote branch:
$ git push origin -delete :branch_name
• Completely remove a branch:
$ git push
origin --delete :branch_name
$ git branch -D
branch_name
Tagging
Tagging
• Create tag:
$ git tag sporting-beta-1 -a -m
'Sporting beta 1 release.'
• Push tag:
$ git push --tags
• List tags:
$ git tag
Tagging
• Move a tag:
$ git tag -f sporting-beta-1
• Delete a tag:
$ git tag -d sporting-beta-1
$
git push origin :sporting-beta-1
Patching
Patching
• $ git diff > [project_name][short_description]-[issue-number][comment-number].patch
• Add the patch file to the root of the module
you patched.
Tips & tricks
Git stash
Git stash
• Store code changes without committing
them.
• Handy when you urgently need to switch
branches.
• Stash your code changes:
$ git stash
• List all available stashes:
$ git stash list
• Most recent stash is shown on top
Git stash
• Apply a stash:
$ git stash apply stash@{0}
Git stash
Git aliases
Git bisect
• Shortcuts
• Define aliases in .gitconfig file.
• Ex: ~/.gitconfig
Git aliases
Git aliases
Git bisect
Git bisect
• Find out in when something broke
• First, find a commit when everything was
working
• Find a commit where things are not working.
• Go to the root of the repository
• $ git bisect start
$ git bisect good fd0a623
$
git bisect bad 256d85
Git bisect
• Refresh the page and see if the bug is there
• $ git bisect good/git bisect bad
• Repeat until git tells you the commit that
broke it
Resources
Resources
• Pro git book: http://git-scm.com/book
• Git bisect tutorial: http://webchick.net/node/99
Questions?

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

Git - Basic Crash Course
Git - Basic Crash CourseGit - Basic Crash Course
Git - Basic Crash Course
 
Gitting out of trouble
Gitting out of troubleGitting out of trouble
Gitting out of trouble
 
Git tutorial
Git tutorialGit tutorial
Git tutorial
 
Git Tutorial I
Git Tutorial IGit Tutorial I
Git Tutorial I
 
Git training
Git trainingGit training
Git training
 
Bitbucket
BitbucketBitbucket
Bitbucket
 
Git: from Novice to Expert
Git: from Novice to ExpertGit: from Novice to Expert
Git: from Novice to Expert
 
Git tutorial
Git tutorialGit tutorial
Git tutorial
 
Git Real
Git RealGit Real
Git Real
 
Git basic
Git basicGit basic
Git basic
 
Introduction to Git (part 1)
Introduction to Git (part 1)Introduction to Git (part 1)
Introduction to Git (part 1)
 
Git tutorial
Git tutorialGit tutorial
Git tutorial
 
Git and GitHub workflows
Git and GitHub workflowsGit and GitHub workflows
Git and GitHub workflows
 
Git Acquainted
Git AcquaintedGit Acquainted
Git Acquainted
 
The everyday developer's guide to version control with Git
The everyday developer's guide to version control with GitThe everyday developer's guide to version control with Git
The everyday developer's guide to version control with Git
 
Using Git and BitBucket
Using Git and BitBucketUsing Git and BitBucket
Using Git and BitBucket
 
Git github
Git githubGit github
Git github
 
Git
GitGit
Git
 
Git101
Git101Git101
Git101
 
Git: basic to advanced
Git: basic to advancedGit: basic to advanced
Git: basic to advanced
 

Semelhante a Git session Dropsolid.com

Introduction to Git and Github
Introduction to Git and Github Introduction to Git and Github
Introduction to Git and Github Max Claus Nunes
 
Introduction To Git Workshop
Introduction To Git WorkshopIntroduction To Git Workshop
Introduction To Git Workshopthemystic_ca
 
Git walkthrough
Git walkthroughGit walkthrough
Git walkthroughBimal Jain
 
Git workshop - University of Moratuwa, Department of Computer Science and Eng...
Git workshop - University of Moratuwa, Department of Computer Science and Eng...Git workshop - University of Moratuwa, Department of Computer Science and Eng...
Git workshop - University of Moratuwa, Department of Computer Science and Eng...WSO2
 
Learning Basic GIT Cmd
Learning Basic GIT CmdLearning Basic GIT Cmd
Learning Basic GIT Cmdsrinathcox
 
Git installation and configuration
Git installation and configurationGit installation and configuration
Git installation and configurationKishor Kumar
 
Git 101 - Crash Course in Version Control using Git
Git 101 - Crash Course in Version Control using GitGit 101 - Crash Course in Version Control using Git
Git 101 - Crash Course in Version Control using GitGeoff Hoffman
 
Git Distributed Version Control System
Git   Distributed Version Control SystemGit   Distributed Version Control System
Git Distributed Version Control SystemVictor Wong
 
Getting some Git
Getting some GitGetting some Git
Getting some GitBADR
 

Semelhante a Git session Dropsolid.com (20)

Git training v10
Git training v10Git training v10
Git training v10
 
Introduction to Git and Github
Introduction to Git and Github Introduction to Git and Github
Introduction to Git and Github
 
Introduction To Git Workshop
Introduction To Git WorkshopIntroduction To Git Workshop
Introduction To Git Workshop
 
sample.pptx
sample.pptxsample.pptx
sample.pptx
 
Git walkthrough
Git walkthroughGit walkthrough
Git walkthrough
 
Git workshop - University of Moratuwa, Department of Computer Science and Eng...
Git workshop - University of Moratuwa, Department of Computer Science and Eng...Git workshop - University of Moratuwa, Department of Computer Science and Eng...
Git workshop - University of Moratuwa, Department of Computer Science and Eng...
 
390a gitintro 12au
390a gitintro 12au390a gitintro 12au
390a gitintro 12au
 
Learning Basic GIT Cmd
Learning Basic GIT CmdLearning Basic GIT Cmd
Learning Basic GIT Cmd
 
Git Tech Talk
Git  Tech TalkGit  Tech Talk
Git Tech Talk
 
Introduction into Git
Introduction into GitIntroduction into Git
Introduction into Git
 
Git101
Git101Git101
Git101
 
Git
Git Git
Git
 
Git installation and configuration
Git installation and configurationGit installation and configuration
Git installation and configuration
 
Git 101 - Crash Course in Version Control using Git
Git 101 - Crash Course in Version Control using GitGit 101 - Crash Course in Version Control using Git
Git 101 - Crash Course in Version Control using Git
 
Git Distributed Version Control System
Git   Distributed Version Control SystemGit   Distributed Version Control System
Git Distributed Version Control System
 
Git basics
Git basicsGit basics
Git basics
 
Getting some Git
Getting some GitGetting some Git
Getting some Git
 
Git and github introduction
Git and github introductionGit and github introduction
Git and github introduction
 
Learn Git Basics
Learn Git BasicsLearn Git Basics
Learn Git Basics
 
git.ppt.pdf
git.ppt.pdfgit.ppt.pdf
git.ppt.pdf
 

Mais de dropsolid

Twig in drupal 8
Twig in drupal 8Twig in drupal 8
Twig in drupal 8dropsolid
 
de Rules module van Drupal
de Rules module van Drupalde Rules module van Drupal
de Rules module van Drupaldropsolid
 
Vertalen met Drupal.
Vertalen met Drupal.Vertalen met Drupal.
Vertalen met Drupal.dropsolid
 
Drupal theming training
Drupal theming trainingDrupal theming training
Drupal theming trainingdropsolid
 
Site building preview - Drupal training
Site building preview - Drupal trainingSite building preview - Drupal training
Site building preview - Drupal trainingdropsolid
 
Drupal Deployment demo
Drupal Deployment demoDrupal Deployment demo
Drupal Deployment demodropsolid
 
Discover Drupal preview
Discover Drupal previewDiscover Drupal preview
Discover Drupal previewdropsolid
 

Mais de dropsolid (7)

Twig in drupal 8
Twig in drupal 8Twig in drupal 8
Twig in drupal 8
 
de Rules module van Drupal
de Rules module van Drupalde Rules module van Drupal
de Rules module van Drupal
 
Vertalen met Drupal.
Vertalen met Drupal.Vertalen met Drupal.
Vertalen met Drupal.
 
Drupal theming training
Drupal theming trainingDrupal theming training
Drupal theming training
 
Site building preview - Drupal training
Site building preview - Drupal trainingSite building preview - Drupal training
Site building preview - Drupal training
 
Drupal Deployment demo
Drupal Deployment demoDrupal Deployment demo
Drupal Deployment demo
 
Discover Drupal preview
Discover Drupal previewDiscover Drupal preview
Discover Drupal preview
 

Último

What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
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
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
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
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
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
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
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
 

Último (20)

What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
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
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
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
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
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
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
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
 

Git session Dropsolid.com