SlideShare ist ein Scribd-Unternehmen logo
1 von 21
Downloaden Sie, um offline zu lesen
Francesco Pira | fpira.com
First steps with Git
Francesco Pira
fpira.com
@pirafrank
me@fpira.com
Linux Day 2016 - Enna (Sicily)
Francesco Pira | fpira.com
Who am I?
• Web developer
• btw currently sys admin
• I like Python
• I’ve founded a startup (no much fuss...)
• I write a blog in my spare time
• ...and some code (github.com/pirafrank)
• I like business
• ...but code is better!
Francesco Pira | fpira.com
What is a VCS?
• VCS stands for Version Control System
• A software to handle different versions of a pool of files
• Great to manage source code
• Something you need to get a job
• Something you need to share your weekend project
• Something you need to deploy and maintain your blog
• See Github Pages, GitLab Pages and Jekyll
Francesco Pira | fpira.com
Why VCS?
• A repository as a unique codebase
• Reliability
• History and changes + easy to roll back at any point
• Blaming (who changed what?)
• Side projects (aka forking a repo)
• Parallel development on the same repo (aka team working)
• Code deployment!
Francesco Pira | fpira.com
Popular VCS software
● Git
● Team Foundation Server (MS)
● Apache Subversion (SVN)
● Mercurial (BitBucket)
● Bazaar (Canonical)
* In order of popularity
Francesco Pira | fpira.com
• repository = a directory with files (usually code!)
• working tree = index of files part of the repo
• ignoring = no to keep track of changes
• staging = virtual area with changes ready to commit
• commit = snapshot of a repository, changes saved in history
• head = pointer to the latest commit of the current branch
• branch = a copy of files to track different changes
• merging = merging the history of a branch with his parent one
• conflict = 2 or more people making changes to same file
• tag = named pointer to a particular snapshot (e.g. v1.1.0)
• remote = server (it can be another PC for distributed VCS)
VCS concepts
Francesco Pira | fpira.com
Who’s Git?
• Created by Linus Torvalds (mid 2005)
• to manage the shared development of Linux kernel
• Today is the most common VCS
• It works using snapshots, pointers and compressed deltas
• All changes and history are in ./.git
• Works best with small files (see git lfs)
• Distribute (remote) architecture
• Used by GitHub: the biggest and de facto standard platform
for sharing open-source code
Francesco Pira | fpira.com
Setup the environment
● Download and install git
○ bit.ly/linux-day-git-install
● Set it up
○ git config --global user.name "My Name"
○ git config --global user.email "my@email.com"
● Remotes require your to have an RSA key: set it up!
○ ssh-keygen -t rsa -b 4096 -C "my@email.com"
○ eval "$(ssh-agent -s)"
○ ssh-add ~/.ssh/id_rsa
Pro tip: Use different RSA keys (personal, work, etc.)
Francesco Pira | fpira.com
Your first commit, yay!
Locally on your computer
• git init
• git add .
• git remote add origin ...
• git commit -m “Hey! This is my first commit”
• git push origin master
Your teammate
• git clone ...
Francesco Pira | fpira.com
Some notes
master is the main and first branch
origin is the primary remote. You push your code to it
Tip: Use --global to make a setting work for all repo of current
local user
Interesting: Git global configuration usually lives here
~/.gitconfig or here ~/.config/git/config
Francesco Pira | fpira.com
Live demo
Francesco Pira | fpira.com
• init = initialise the repository (make ./.git subdir)
• clone = make a local copy of the repo from a remote one
• diff = show current changes (before staging them)
• add = stage one of more file / folders
• commit = make a ‘snapshot’ / save a state
• branch = create a branch off the current one
• merge = merge a branch into his parent
• fetch = download (new) changes from remote
• pull = fetch from remote branch + merge to local one
• checkout = switch branch / restore file in working tree
• reset = undo / remove from staging area
• log = explore changes history
• … tons of commands, each one has tons of parameters: RTFM!
Main Git commands
Francesco Pira | fpira.com
Lazy as a pig? Aliases!
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.st 'status -s'
git config --global alias.unstage 'reset HEAD --'
...Make yours!
Francesco Pira | fpira.com
Best practices
• Don’t zip repositories! Use remotes!
• master as the main branch
• devel as the main development branch
• all features start off devel
• all features ends
• usually you don’t push features
• all releases must be tagged (in master)
• use semantic versioning for tags
• hotfix start off master, merged to master and devel
Francesco Pira | fpira.com
Credits to Vincent Driessen
Francesco Pira | fpira.com
Live demo
Francesco Pira | fpira.com
UI clients
● Windows and macOS
○ Sourcetree
● Linux
○ SmartGit
Francesco Pira | fpira.com
Best platforms
● GitHub
○ Free only for open-source public projects
● BitBucket
○ Free for unlimited private or public repos (any license)
○ Paid for 5+ collaborators
● GitLab
○ Paid enterprise version (with support)
○ Free Community Edition (self-hosted)
○ Free gitlab.com: unlimited repos, unlimited collaborators
Francesco Pira | fpira.com
Your turn!
• Wow! git log --graph --oneline --decorate --all
• Discover git stash and git pop
• Deploy best practices
• Use git-flow
• Deploy a web application using git
• Try git-lfs
• ...Have fun!
Francesco Pira | fpira.com
Sources and extras
• https://git-scm.com/book/en/v2/Getting-Started-Git-Basics
• https://help.github.com/articles/generating-a-new-ssh-key-and-addi
ng-it-to-the-ssh-agent/
• https://www.atlassian.com/git/tutorials
• http://nvie.com/posts/a-successful-git-branching-model/
• http://semver.org (semantic versioning)
Francesco Pira | fpira.com
Thank you!
Keep in touch
fpira.com
@pirafrank
me@fpira.com
github.com/ pirafrank

Weitere ähnliche Inhalte

Kürzlich hochgeladen

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 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, Adobeapidays
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
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...Martijn de Jong
 
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 2024The Digital Insurer
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
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)wesley chun
 
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.pptxRustici Software
 
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...Zilliz
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
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 ModelDeepika Singh
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbuapidays
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 

Kürzlich hochgeladen (20)

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 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
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
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...
 
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
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
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)
 
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
 
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...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
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
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 

Empfohlen

Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 

Empfohlen (20)

Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 

First steps with Git - Linux Day 2016 - Enna

  • 1. Francesco Pira | fpira.com First steps with Git Francesco Pira fpira.com @pirafrank me@fpira.com Linux Day 2016 - Enna (Sicily)
  • 2. Francesco Pira | fpira.com Who am I? • Web developer • btw currently sys admin • I like Python • I’ve founded a startup (no much fuss...) • I write a blog in my spare time • ...and some code (github.com/pirafrank) • I like business • ...but code is better!
  • 3. Francesco Pira | fpira.com What is a VCS? • VCS stands for Version Control System • A software to handle different versions of a pool of files • Great to manage source code • Something you need to get a job • Something you need to share your weekend project • Something you need to deploy and maintain your blog • See Github Pages, GitLab Pages and Jekyll
  • 4. Francesco Pira | fpira.com Why VCS? • A repository as a unique codebase • Reliability • History and changes + easy to roll back at any point • Blaming (who changed what?) • Side projects (aka forking a repo) • Parallel development on the same repo (aka team working) • Code deployment!
  • 5. Francesco Pira | fpira.com Popular VCS software ● Git ● Team Foundation Server (MS) ● Apache Subversion (SVN) ● Mercurial (BitBucket) ● Bazaar (Canonical) * In order of popularity
  • 6. Francesco Pira | fpira.com • repository = a directory with files (usually code!) • working tree = index of files part of the repo • ignoring = no to keep track of changes • staging = virtual area with changes ready to commit • commit = snapshot of a repository, changes saved in history • head = pointer to the latest commit of the current branch • branch = a copy of files to track different changes • merging = merging the history of a branch with his parent one • conflict = 2 or more people making changes to same file • tag = named pointer to a particular snapshot (e.g. v1.1.0) • remote = server (it can be another PC for distributed VCS) VCS concepts
  • 7. Francesco Pira | fpira.com Who’s Git? • Created by Linus Torvalds (mid 2005) • to manage the shared development of Linux kernel • Today is the most common VCS • It works using snapshots, pointers and compressed deltas • All changes and history are in ./.git • Works best with small files (see git lfs) • Distribute (remote) architecture • Used by GitHub: the biggest and de facto standard platform for sharing open-source code
  • 8. Francesco Pira | fpira.com Setup the environment ● Download and install git ○ bit.ly/linux-day-git-install ● Set it up ○ git config --global user.name "My Name" ○ git config --global user.email "my@email.com" ● Remotes require your to have an RSA key: set it up! ○ ssh-keygen -t rsa -b 4096 -C "my@email.com" ○ eval "$(ssh-agent -s)" ○ ssh-add ~/.ssh/id_rsa Pro tip: Use different RSA keys (personal, work, etc.)
  • 9. Francesco Pira | fpira.com Your first commit, yay! Locally on your computer • git init • git add . • git remote add origin ... • git commit -m “Hey! This is my first commit” • git push origin master Your teammate • git clone ...
  • 10. Francesco Pira | fpira.com Some notes master is the main and first branch origin is the primary remote. You push your code to it Tip: Use --global to make a setting work for all repo of current local user Interesting: Git global configuration usually lives here ~/.gitconfig or here ~/.config/git/config
  • 11. Francesco Pira | fpira.com Live demo
  • 12. Francesco Pira | fpira.com • init = initialise the repository (make ./.git subdir) • clone = make a local copy of the repo from a remote one • diff = show current changes (before staging them) • add = stage one of more file / folders • commit = make a ‘snapshot’ / save a state • branch = create a branch off the current one • merge = merge a branch into his parent • fetch = download (new) changes from remote • pull = fetch from remote branch + merge to local one • checkout = switch branch / restore file in working tree • reset = undo / remove from staging area • log = explore changes history • … tons of commands, each one has tons of parameters: RTFM! Main Git commands
  • 13. Francesco Pira | fpira.com Lazy as a pig? Aliases! git config --global alias.co checkout git config --global alias.br branch git config --global alias.ci commit git config --global alias.st 'status -s' git config --global alias.unstage 'reset HEAD --' ...Make yours!
  • 14. Francesco Pira | fpira.com Best practices • Don’t zip repositories! Use remotes! • master as the main branch • devel as the main development branch • all features start off devel • all features ends • usually you don’t push features • all releases must be tagged (in master) • use semantic versioning for tags • hotfix start off master, merged to master and devel
  • 15. Francesco Pira | fpira.com Credits to Vincent Driessen
  • 16. Francesco Pira | fpira.com Live demo
  • 17. Francesco Pira | fpira.com UI clients ● Windows and macOS ○ Sourcetree ● Linux ○ SmartGit
  • 18. Francesco Pira | fpira.com Best platforms ● GitHub ○ Free only for open-source public projects ● BitBucket ○ Free for unlimited private or public repos (any license) ○ Paid for 5+ collaborators ● GitLab ○ Paid enterprise version (with support) ○ Free Community Edition (self-hosted) ○ Free gitlab.com: unlimited repos, unlimited collaborators
  • 19. Francesco Pira | fpira.com Your turn! • Wow! git log --graph --oneline --decorate --all • Discover git stash and git pop • Deploy best practices • Use git-flow • Deploy a web application using git • Try git-lfs • ...Have fun!
  • 20. Francesco Pira | fpira.com Sources and extras • https://git-scm.com/book/en/v2/Getting-Started-Git-Basics • https://help.github.com/articles/generating-a-new-ssh-key-and-addi ng-it-to-the-ssh-agent/ • https://www.atlassian.com/git/tutorials • http://nvie.com/posts/a-successful-git-branching-model/ • http://semver.org (semantic versioning)
  • 21. Francesco Pira | fpira.com Thank you! Keep in touch fpira.com @pirafrank me@fpira.com github.com/ pirafrank