SlideShare una empresa de 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?

Más contenido relacionado

La actualidad más candente

Using Git and BitBucket
Using Git and BitBucketUsing Git and BitBucket
Using Git and BitBucket
Medhat Dawoud
 

La actualidad más candente (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
 

Similar a Git session Dropsolid.com

Git Distributed Version Control System
Git   Distributed Version Control SystemGit   Distributed Version Control System
Git Distributed Version Control System
Victor Wong
 

Similar 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 and Github workshop GDSC MLRITM
Git and Github  workshop GDSC MLRITMGit and Github  workshop GDSC MLRITM
Git and Github workshop GDSC MLRITM
 
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
 

Más 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

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Último (20)

Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
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
 
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
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 

Git session Dropsolid.com