SlideShare une entreprise Scribd logo
1  sur  54
Télécharger pour lire hors ligne
Practical git for developers
(aka 'Git for beginners')
Wim Godden
Cu.be Solutions
@wimgtr
Who am I ?
Wim Godden (@wimgtr)
Where I'm from
Where I'm from
Where I'm from
Where I'm from
Where I'm from
Where I'm from
My town
My town
Belgium – the traffic
Who am I ?
Wim Godden (@wimgtr)
Founder of Cu.be Solutions (http://cu.be)
Open Source developer since 1997
Developer of PHPCompatibility, OpenX, PHPConsistent, ...
Speaker at Open Source conferences
Who are you ?
Developers ?
CVS ?
SVN ?
TFS ?
Git ?
What is git ?
Git is a file system
with a Version Control System on top of it
Git's file structure
Commit
tree
author_info
parent
Tree
README.MD
LICENSE
index.php
Blob
datadatadata...
Blob
datadatadata...
Blob
datadatadata...
6d3af... 8a3ea...
901a3...
4a39c...
e3231...
8a3ea... 901a3...
4a39c...
e3231...
What is git ?
Git is a file system
with a Version Control System on top of it
What is git ?
Git is a distributed file system
with a Version Control System on top of it
(Almost) everything is local
Clone = copy of entire repository
Work offline :
Perform a diff
View file history
Commit changes (!)
Create, merge or switch branches
etc.
Only push/pull are not local
(Almost) everything is immutable
Immutable = doesn't change
Once placed in git, it stays there
Even if you delete files
Differences with SVN
SVN keeps diffs between versions
Git keeps full snapshots
Commit #1
tree
author_info
parent
Tree
README.MD
Commit #2
tree
author_info
parent
Tree
README.MD
index.php
Commit #3
tree
author_info
parent
Tree
README.MD
LICENSE
index.php
Differences with SVN
SVN is centralized
↔ Git is distributed
An SVN commit → shared with everyone
↔ A Git commit is local
SVN has revision increments
↔ Git has SHA1 hashes to identify objects
(commits, trees, blobs, ...)
Basic git – config
$ git config --global user.name "Wim Godden"
$ git config --global user.email "wim.godden@cu.be"
$ git config --global core.editor vim
$ git config --global core.autocrlf input
$ git config --global core.autocrlf true
$ git config --global color.ui true
(on Linux)
(on Windows)
Basic git - .gitignore
Allows you to specify files to ignore
Can be specific to repository
Hint : set up a global .gitignore for :
thumbnail.dat
desktop.ini
.DS_Store
Your local editor's files
…
Create a repo
$ git init
$ tree .git
.git/
├── branches
├── config
├── description
├── HEAD
├── info
│   └── exclude
├── objects
│   ├── info
│   └── pack
└── refs
├── heads
└── tags
.git directory
config – Configuration file
refs/heads/... - branches
refs/tags/... - tags
refs/remotes/... - remotes
objects/... - the actual objects
HEAD – the current working space, points to one of branches
git clone
Creates a repository from an existing repository
git clone https://someplace.com/repo.git <somefolder>
Original repository is called 'origin'
→ This is called a 'remote'
Git flow
Working directory
Staging area
Repository
Remote(s)
Add
Commit
Push
git status
Simple command
Explains in clear language what's going on
Use it, use it, use it, ...
Git flow
Working directory
Staging area
Repository
Remote(s)
Add
Commit
Push
git add
Add file in current state to the staging area
Can be new file
Can be modification
git add -A stages all
git add . stages new and modified, but no deletions
git add -u stages modified and deleted, but no new files
git reset
Unstage changes
Revert to older commit version
Beware : dangerous command !
Remove files from repository
2 ways :
Delete, then rm
Delete the file from working directory
git rm <filename>
Commit
Just rm
git rm <filename>
Commit
Accidentially deleted ?
→ git checkout -- <filename>
Git flow
Working directory
Staging area
Repository
Remote(s)
Add
Commit
Push
git commit
Creates a new version
Based on the staging area
Commits on local repository only
Commit #1
tree
author_info
parent
Tree
README.MD
Commit #2
tree
author_info
parent : #1
Tree
README.MD
index.php
Commit #3
tree
author_info
parent : #2
Tree
README.MD
LICENSE
index.php
HEAD
git log
Shows each commit with SHA1 hash
→ hash can be used with other commands
-p gives a diff view
git diff
No params : default diff output
git diff --staged : diff with what's been staged
Clone, add, commit and push
C1
Remote originLocal repository
C2
master
C1 C2
origin/master
1 2
C1 C2
origin/master
C3
master HEAD
master HEAD1
2 C1 C2
master
C1 C2
origin/master
C3
master HEAD
3
3
C1 C2
master
C3
Working with remotes
git push
→ Send locally commited changes to the remote repository
git fetch/pull
→ Retrieve changes from the remote repository
Fetch, merge and pull
Remote originLocal repository
C1 C2
origin/master
1 2
C1 C2
origin/master
C3
master HEAD
master HEAD
1
C1 C2 C3
master HEAD
2
3
C1 C2
master
C3C2
origin/master 3
git fetch + merge vs git pull
git fetch : fetches information from remote into local repository
but nothing more
git merge : merges changes that were fetched
needs a source parameter
merges TO wherever HEAD is pointing to :
git merge origin/master
git pull : does both at the same time
Branches
Branches are separate full-blown versions of your code
Default branch = master
Which branches are there ? → git branch
Create a new branch → git branch <branchname>
Switch to branch → git checkout <branchname>
Create + switch to new branch → git checkout -b <branchname>
Show branch activity : git show-branch
Delete a branch : git branch -d <branchname>
Merging changes in a project
C1 C2
origin/master
C1 C2
origin/master
C3
master
master
C4 test
LICENSE : added paragraph 1
LICENSE : added paragraph 2
C1 C2
origin/master
C3 master
C4 test
LICENSE : added paragraph 1 + 2
Edited LICENSE
C5
Conflicting change
git merge <branchname> → conflict
git status → shows conflicted files
Resolve conflict
git commit -a → tells git conflict was resolved
Contributing to a Github project
Github is built on Git, so...
Clone, commit, pull, merge, push are all the same
But :
You need to fork the project first
Changes to the main repository must be requested through a
pull request
Creating a fork
Creating a fork
Will create a complete copy (not a clone) of the project
Including master, all branches, all tags, all commits, etc.
i.e. confoo/some-repo → <your_github_username>/some-repo
You can do anything in it...
But please don't if you intend to contribute back...
Which you should ofcourse ;-)
Next : create a branch for your feature/bugfix
Why ?
Work on multiple features/fixes at same time
Experiment without damaging your master
master should always be a fully functioning, deployable version
Name the branch well
Don't : bugfix
Do : bugfix_issue_26_fatal_error
Next : add/change code and commit
Don't forget unit tests, integration tests, …
Make your commit message descriptive
Don't : fixed it
Do : added real-time updates on dashboard
Each commit should contain a single feature or bugfix
→ Allows project maintainers to add small blocks of code
→ Easier than adding 50 features/bugfixes
→ Easier to test
Next : create a Pull Request (PR)
When you want to contribute
Partial code = OK
→ But only if you want feedback
Otherwise :
Finish your code
Make sure you have unit tests
Be descriptive in your pull request
Don't : “this will fix my issues”
Do : “Added an OAuth authentication layer”
Next : merging the PR
Done by a project maintainer (could be you !)
Merge from the PR branch to master
Again : have a clear merge message
→ On Github : 'Closes #56' will close Github issue and links
Congratulations, you're a Github contributor ;-)
Git tools
git-cola (Linux, Win, Mac)
GitHub Desktop (Win, Mac)
GitKraken (Linux, Win, Mac) - beta
Liquid prompt
Useful list :
https://git.wiki.kernel.org/index.php/Interfaces,_frontends,_and_tools
Questions ?
Questions ?
Thanks !
@wimgtr
wim@cu.be

Contenu connexe

Tendances

An Introduction to Tornado
An Introduction to TornadoAn Introduction to Tornado
An Introduction to TornadoGavin Roy
 
Tornado web
Tornado webTornado web
Tornado webkurtiss
 
Syncing up with Python’s asyncio for (micro) service development, Joir-dan Gumbs
Syncing up with Python’s asyncio for (micro) service development, Joir-dan GumbsSyncing up with Python’s asyncio for (micro) service development, Joir-dan Gumbs
Syncing up with Python’s asyncio for (micro) service development, Joir-dan GumbsPôle Systematic Paris-Region
 
Python, async web frameworks, and MongoDB
Python, async web frameworks, and MongoDBPython, async web frameworks, and MongoDB
Python, async web frameworks, and MongoDBemptysquare
 
Tornado - different Web programming
Tornado - different Web programmingTornado - different Web programming
Tornado - different Web programmingDima Malenko
 
Composer - Package Management for PHP. Silver Bullet?
Composer - Package Management for PHP. Silver Bullet?Composer - Package Management for PHP. Silver Bullet?
Composer - Package Management for PHP. Silver Bullet?Kirill Chebunin
 
Shared Object images in Docker: What you need is what you want.
Shared Object images in Docker: What you need is what you want.Shared Object images in Docker: What you need is what you want.
Shared Object images in Docker: What you need is what you want.Workhorse Computing
 
Nginx + Tornado = 17k req/s
Nginx + Tornado = 17k req/sNginx + Tornado = 17k req/s
Nginx + Tornado = 17k req/smoret1979
 
PSGI and Plack from first principles
PSGI and Plack from first principlesPSGI and Plack from first principles
PSGI and Plack from first principlesPerl Careers
 
Construire son JDK en 10 étapes
Construire son JDK en 10 étapesConstruire son JDK en 10 étapes
Construire son JDK en 10 étapesJosé Paumard
 
Real-Time Web Apps & Symfony. What are your options?
Real-Time Web Apps & Symfony. What are your options?Real-Time Web Apps & Symfony. What are your options?
Real-Time Web Apps & Symfony. What are your options?Phil Leggetter
 
Puppet at GitHub - PuppetConf 2013
Puppet at GitHub - PuppetConf 2013Puppet at GitHub - PuppetConf 2013
Puppet at GitHub - PuppetConf 2013Puppet
 
Webinar: Building Your First App in Node.js
Webinar: Building Your First App in Node.jsWebinar: Building Your First App in Node.js
Webinar: Building Your First App in Node.jsMongoDB
 
Composer the right way - SunshinePHP
Composer the right way - SunshinePHPComposer the right way - SunshinePHP
Composer the right way - SunshinePHPRafael Dohms
 
Java Libraries You Can’t Afford to Miss
Java Libraries You Can’t Afford to MissJava Libraries You Can’t Afford to Miss
Java Libraries You Can’t Afford to MissAndres Almiray
 
Going native with less coupling: Dependency Injection in C++
Going native with less coupling: Dependency Injection in C++Going native with less coupling: Dependency Injection in C++
Going native with less coupling: Dependency Injection in C++Daniele Pallastrelli
 

Tendances (20)

An Introduction to Tornado
An Introduction to TornadoAn Introduction to Tornado
An Introduction to Tornado
 
Tornado web
Tornado webTornado web
Tornado web
 
Designing net-aws-glacier
Designing net-aws-glacierDesigning net-aws-glacier
Designing net-aws-glacier
 
Syncing up with Python’s asyncio for (micro) service development, Joir-dan Gumbs
Syncing up with Python’s asyncio for (micro) service development, Joir-dan GumbsSyncing up with Python’s asyncio for (micro) service development, Joir-dan Gumbs
Syncing up with Python’s asyncio for (micro) service development, Joir-dan Gumbs
 
Python, async web frameworks, and MongoDB
Python, async web frameworks, and MongoDBPython, async web frameworks, and MongoDB
Python, async web frameworks, and MongoDB
 
Tornado - different Web programming
Tornado - different Web programmingTornado - different Web programming
Tornado - different Web programming
 
Composer - Package Management for PHP. Silver Bullet?
Composer - Package Management for PHP. Silver Bullet?Composer - Package Management for PHP. Silver Bullet?
Composer - Package Management for PHP. Silver Bullet?
 
Shared Object images in Docker: What you need is what you want.
Shared Object images in Docker: What you need is what you want.Shared Object images in Docker: What you need is what you want.
Shared Object images in Docker: What you need is what you want.
 
Nginx + Tornado = 17k req/s
Nginx + Tornado = 17k req/sNginx + Tornado = 17k req/s
Nginx + Tornado = 17k req/s
 
Tornadoweb
TornadowebTornadoweb
Tornadoweb
 
PSGI and Plack from first principles
PSGI and Plack from first principlesPSGI and Plack from first principles
PSGI and Plack from first principles
 
groovy & grails - lecture 13
groovy & grails - lecture 13groovy & grails - lecture 13
groovy & grails - lecture 13
 
Construire son JDK en 10 étapes
Construire son JDK en 10 étapesConstruire son JDK en 10 étapes
Construire son JDK en 10 étapes
 
Real-Time Web Apps & Symfony. What are your options?
Real-Time Web Apps & Symfony. What are your options?Real-Time Web Apps & Symfony. What are your options?
Real-Time Web Apps & Symfony. What are your options?
 
Puppet at GitHub - PuppetConf 2013
Puppet at GitHub - PuppetConf 2013Puppet at GitHub - PuppetConf 2013
Puppet at GitHub - PuppetConf 2013
 
Webinar: Building Your First App in Node.js
Webinar: Building Your First App in Node.jsWebinar: Building Your First App in Node.js
Webinar: Building Your First App in Node.js
 
Composer the right way - SunshinePHP
Composer the right way - SunshinePHPComposer the right way - SunshinePHP
Composer the right way - SunshinePHP
 
Java Libraries You Can’t Afford to Miss
Java Libraries You Can’t Afford to MissJava Libraries You Can’t Afford to Miss
Java Libraries You Can’t Afford to Miss
 
groovy & grails - lecture 10
groovy & grails - lecture 10groovy & grails - lecture 10
groovy & grails - lecture 10
 
Going native with less coupling: Dependency Injection in C++
Going native with less coupling: Dependency Injection in C++Going native with less coupling: Dependency Injection in C++
Going native with less coupling: Dependency Injection in C++
 

Similaire à Practical git for developers

Using Github for DSpace development
Using Github for DSpace developmentUsing Github for DSpace development
Using Github for DSpace developmentBram Luyten
 
Git the Docs: A fun, hands-on introduction to version control
Git the Docs: A fun, hands-on introduction to version controlGit the Docs: A fun, hands-on introduction to version control
Git the Docs: A fun, hands-on introduction to version controlBecky Todd
 
Understanding about git
Understanding about gitUnderstanding about git
Understanding about gitSothearin Ren
 
GIT in a nutshell
GIT in a nutshellGIT in a nutshell
GIT in a nutshellalignan
 
Introduction to GitHub, Open Source and Tech Article
Introduction to GitHub, Open Source and Tech ArticleIntroduction to GitHub, Open Source and Tech Article
Introduction to GitHub, Open Source and Tech ArticlePRIYATHAMDARISI
 
Git, from the beginning
Git, from the beginningGit, from the beginning
Git, from the beginningJames Aylett
 
Working in Team using Git in Unity
Working in Team using Git in UnityWorking in Team using Git in Unity
Working in Team using Git in UnityRifauddin Tsalitsy
 
Github - Git Training Slides: Foundations
Github - Git Training Slides: FoundationsGithub - Git Training Slides: Foundations
Github - Git Training Slides: FoundationsLee Hanxue
 
Git for developers
Git for developersGit for developers
Git for developersHacen Dadda
 
Git 101 Workshop
Git 101 WorkshopGit 101 Workshop
Git 101 WorkshopJoy Seng
 

Similaire à Practical git for developers (20)

Git training
Git trainingGit training
Git training
 
Introduction to Git (Greg Lonnon)
Introduction to Git (Greg Lonnon)Introduction to Git (Greg Lonnon)
Introduction to Git (Greg Lonnon)
 
Using Github for DSpace development
Using Github for DSpace developmentUsing Github for DSpace development
Using Github for DSpace development
 
Git the Docs: A fun, hands-on introduction to version control
Git the Docs: A fun, hands-on introduction to version controlGit the Docs: A fun, hands-on introduction to version control
Git the Docs: A fun, hands-on introduction to version control
 
Git
GitGit
Git
 
Understanding about git
Understanding about gitUnderstanding about git
Understanding about git
 
GIT in a nutshell
GIT in a nutshellGIT in a nutshell
GIT in a nutshell
 
GitSetupLinux
GitSetupLinuxGitSetupLinux
GitSetupLinux
 
Git setuplinux
Git setuplinuxGit setuplinux
Git setuplinux
 
Git
GitGit
Git
 
1-Intro to VC & GIT PDF.pptx
1-Intro to VC & GIT PDF.pptx1-Intro to VC & GIT PDF.pptx
1-Intro to VC & GIT PDF.pptx
 
Introduction to GitHub, Open Source and Tech Article
Introduction to GitHub, Open Source and Tech ArticleIntroduction to GitHub, Open Source and Tech Article
Introduction to GitHub, Open Source and Tech Article
 
Switching to Git
Switching to GitSwitching to Git
Switching to Git
 
Git, from the beginning
Git, from the beginningGit, from the beginning
Git, from the beginning
 
Working in Team using Git in Unity
Working in Team using Git in UnityWorking in Team using Git in Unity
Working in Team using Git in Unity
 
Git
GitGit
Git
 
Github - Git Training Slides: Foundations
Github - Git Training Slides: FoundationsGithub - Git Training Slides: Foundations
Github - Git Training Slides: Foundations
 
Git for developers
Git for developersGit for developers
Git for developers
 
How to use git without rage
How to use git without rageHow to use git without rage
How to use git without rage
 
Git 101 Workshop
Git 101 WorkshopGit 101 Workshop
Git 101 Workshop
 

Plus de Wim Godden

Beyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeBeyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeWim Godden
 
Bringing bright ideas to life
Bringing bright ideas to lifeBringing bright ideas to life
Bringing bright ideas to lifeWim Godden
 
The why and how of moving to php 8
The why and how of moving to php 8The why and how of moving to php 8
The why and how of moving to php 8Wim Godden
 
The why and how of moving to php 7
The why and how of moving to php 7The why and how of moving to php 7
The why and how of moving to php 7Wim Godden
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I thinkWim Godden
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I thinkWim Godden
 
Building interactivity with websockets
Building interactivity with websocketsBuilding interactivity with websockets
Building interactivity with websocketsWim Godden
 
Bringing bright ideas to life
Bringing bright ideas to lifeBringing bright ideas to life
Bringing bright ideas to lifeWim Godden
 
Your app lives on the network - networking for web developers
Your app lives on the network - networking for web developersYour app lives on the network - networking for web developers
Your app lives on the network - networking for web developersWim Godden
 
The why and how of moving to php 7.x
The why and how of moving to php 7.xThe why and how of moving to php 7.x
The why and how of moving to php 7.xWim Godden
 
The why and how of moving to php 7.x
The why and how of moving to php 7.xThe why and how of moving to php 7.x
The why and how of moving to php 7.xWim Godden
 
Beyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeBeyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeWim Godden
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I thinkWim Godden
 
Building interactivity with websockets
Building interactivity with websocketsBuilding interactivity with websockets
Building interactivity with websocketsWim Godden
 
Your app lives on the network - networking for web developers
Your app lives on the network - networking for web developersYour app lives on the network - networking for web developers
Your app lives on the network - networking for web developersWim Godden
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I thinkWim Godden
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I thinkWim Godden
 
The promise of asynchronous php
The promise of asynchronous phpThe promise of asynchronous php
The promise of asynchronous phpWim Godden
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I thinkWim Godden
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I thinkWim Godden
 

Plus de Wim Godden (20)

Beyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeBeyond php - it's not (just) about the code
Beyond php - it's not (just) about the code
 
Bringing bright ideas to life
Bringing bright ideas to lifeBringing bright ideas to life
Bringing bright ideas to life
 
The why and how of moving to php 8
The why and how of moving to php 8The why and how of moving to php 8
The why and how of moving to php 8
 
The why and how of moving to php 7
The why and how of moving to php 7The why and how of moving to php 7
The why and how of moving to php 7
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I think
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I think
 
Building interactivity with websockets
Building interactivity with websocketsBuilding interactivity with websockets
Building interactivity with websockets
 
Bringing bright ideas to life
Bringing bright ideas to lifeBringing bright ideas to life
Bringing bright ideas to life
 
Your app lives on the network - networking for web developers
Your app lives on the network - networking for web developersYour app lives on the network - networking for web developers
Your app lives on the network - networking for web developers
 
The why and how of moving to php 7.x
The why and how of moving to php 7.xThe why and how of moving to php 7.x
The why and how of moving to php 7.x
 
The why and how of moving to php 7.x
The why and how of moving to php 7.xThe why and how of moving to php 7.x
The why and how of moving to php 7.x
 
Beyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeBeyond php - it's not (just) about the code
Beyond php - it's not (just) about the code
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I think
 
Building interactivity with websockets
Building interactivity with websocketsBuilding interactivity with websockets
Building interactivity with websockets
 
Your app lives on the network - networking for web developers
Your app lives on the network - networking for web developersYour app lives on the network - networking for web developers
Your app lives on the network - networking for web developers
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I think
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I think
 
The promise of asynchronous php
The promise of asynchronous phpThe promise of asynchronous php
The promise of asynchronous php
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I think
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I think
 

Dernier

Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
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
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
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
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
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
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
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
 
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
 

Dernier (20)

Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
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
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
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
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
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
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
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
 
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
 
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
 

Practical git for developers

  • 1. Practical git for developers (aka 'Git for beginners') Wim Godden Cu.be Solutions @wimgtr
  • 2. Who am I ? Wim Godden (@wimgtr)
  • 11. Belgium – the traffic
  • 12. Who am I ? Wim Godden (@wimgtr) Founder of Cu.be Solutions (http://cu.be) Open Source developer since 1997 Developer of PHPCompatibility, OpenX, PHPConsistent, ... Speaker at Open Source conferences
  • 13. Who are you ? Developers ? CVS ? SVN ? TFS ? Git ?
  • 14. What is git ? Git is a file system with a Version Control System on top of it
  • 16. What is git ? Git is a file system with a Version Control System on top of it
  • 17. What is git ? Git is a distributed file system with a Version Control System on top of it
  • 18. (Almost) everything is local Clone = copy of entire repository Work offline : Perform a diff View file history Commit changes (!) Create, merge or switch branches etc. Only push/pull are not local
  • 19. (Almost) everything is immutable Immutable = doesn't change Once placed in git, it stays there Even if you delete files
  • 20. Differences with SVN SVN keeps diffs between versions Git keeps full snapshots Commit #1 tree author_info parent Tree README.MD Commit #2 tree author_info parent Tree README.MD index.php Commit #3 tree author_info parent Tree README.MD LICENSE index.php
  • 21. Differences with SVN SVN is centralized ↔ Git is distributed An SVN commit → shared with everyone ↔ A Git commit is local SVN has revision increments ↔ Git has SHA1 hashes to identify objects (commits, trees, blobs, ...)
  • 22. Basic git – config $ git config --global user.name "Wim Godden" $ git config --global user.email "wim.godden@cu.be" $ git config --global core.editor vim $ git config --global core.autocrlf input $ git config --global core.autocrlf true $ git config --global color.ui true (on Linux) (on Windows)
  • 23. Basic git - .gitignore Allows you to specify files to ignore Can be specific to repository Hint : set up a global .gitignore for : thumbnail.dat desktop.ini .DS_Store Your local editor's files …
  • 24. Create a repo $ git init $ tree .git .git/ ├── branches ├── config ├── description ├── HEAD ├── info │   └── exclude ├── objects │   ├── info │   └── pack └── refs ├── heads └── tags
  • 25. .git directory config – Configuration file refs/heads/... - branches refs/tags/... - tags refs/remotes/... - remotes objects/... - the actual objects HEAD – the current working space, points to one of branches
  • 26. git clone Creates a repository from an existing repository git clone https://someplace.com/repo.git <somefolder> Original repository is called 'origin' → This is called a 'remote'
  • 27. Git flow Working directory Staging area Repository Remote(s) Add Commit Push
  • 28. git status Simple command Explains in clear language what's going on Use it, use it, use it, ...
  • 29. Git flow Working directory Staging area Repository Remote(s) Add Commit Push
  • 30. git add Add file in current state to the staging area Can be new file Can be modification git add -A stages all git add . stages new and modified, but no deletions git add -u stages modified and deleted, but no new files
  • 31. git reset Unstage changes Revert to older commit version Beware : dangerous command !
  • 32. Remove files from repository 2 ways : Delete, then rm Delete the file from working directory git rm <filename> Commit Just rm git rm <filename> Commit Accidentially deleted ? → git checkout -- <filename>
  • 33. Git flow Working directory Staging area Repository Remote(s) Add Commit Push
  • 34. git commit Creates a new version Based on the staging area Commits on local repository only Commit #1 tree author_info parent Tree README.MD Commit #2 tree author_info parent : #1 Tree README.MD index.php Commit #3 tree author_info parent : #2 Tree README.MD LICENSE index.php HEAD
  • 35. git log Shows each commit with SHA1 hash → hash can be used with other commands -p gives a diff view
  • 36. git diff No params : default diff output git diff --staged : diff with what's been staged
  • 37. Clone, add, commit and push C1 Remote originLocal repository C2 master C1 C2 origin/master 1 2 C1 C2 origin/master C3 master HEAD master HEAD1 2 C1 C2 master C1 C2 origin/master C3 master HEAD 3 3 C1 C2 master C3
  • 38. Working with remotes git push → Send locally commited changes to the remote repository git fetch/pull → Retrieve changes from the remote repository
  • 39. Fetch, merge and pull Remote originLocal repository C1 C2 origin/master 1 2 C1 C2 origin/master C3 master HEAD master HEAD 1 C1 C2 C3 master HEAD 2 3 C1 C2 master C3C2 origin/master 3
  • 40. git fetch + merge vs git pull git fetch : fetches information from remote into local repository but nothing more git merge : merges changes that were fetched needs a source parameter merges TO wherever HEAD is pointing to : git merge origin/master git pull : does both at the same time
  • 41. Branches Branches are separate full-blown versions of your code Default branch = master Which branches are there ? → git branch Create a new branch → git branch <branchname> Switch to branch → git checkout <branchname> Create + switch to new branch → git checkout -b <branchname> Show branch activity : git show-branch Delete a branch : git branch -d <branchname>
  • 42. Merging changes in a project C1 C2 origin/master C1 C2 origin/master C3 master master C4 test LICENSE : added paragraph 1 LICENSE : added paragraph 2 C1 C2 origin/master C3 master C4 test LICENSE : added paragraph 1 + 2 Edited LICENSE C5
  • 43. Conflicting change git merge <branchname> → conflict git status → shows conflicted files Resolve conflict git commit -a → tells git conflict was resolved
  • 44. Contributing to a Github project Github is built on Git, so... Clone, commit, pull, merge, push are all the same But : You need to fork the project first Changes to the main repository must be requested through a pull request
  • 46. Creating a fork Will create a complete copy (not a clone) of the project Including master, all branches, all tags, all commits, etc. i.e. confoo/some-repo → <your_github_username>/some-repo You can do anything in it... But please don't if you intend to contribute back... Which you should ofcourse ;-)
  • 47. Next : create a branch for your feature/bugfix Why ? Work on multiple features/fixes at same time Experiment without damaging your master master should always be a fully functioning, deployable version Name the branch well Don't : bugfix Do : bugfix_issue_26_fatal_error
  • 48. Next : add/change code and commit Don't forget unit tests, integration tests, … Make your commit message descriptive Don't : fixed it Do : added real-time updates on dashboard Each commit should contain a single feature or bugfix → Allows project maintainers to add small blocks of code → Easier than adding 50 features/bugfixes → Easier to test
  • 49. Next : create a Pull Request (PR) When you want to contribute Partial code = OK → But only if you want feedback Otherwise : Finish your code Make sure you have unit tests Be descriptive in your pull request Don't : “this will fix my issues” Do : “Added an OAuth authentication layer”
  • 50. Next : merging the PR Done by a project maintainer (could be you !) Merge from the PR branch to master Again : have a clear merge message → On Github : 'Closes #56' will close Github issue and links Congratulations, you're a Github contributor ;-)
  • 51. Git tools git-cola (Linux, Win, Mac) GitHub Desktop (Win, Mac) GitKraken (Linux, Win, Mac) - beta Liquid prompt Useful list : https://git.wiki.kernel.org/index.php/Interfaces,_frontends,_and_tools

Notes de l'éditeur

  1. git clone [email_address]:wimg/confoodemo.git
  2. * = current brach + = commit is in the branch - = commit is in the branch as a merge
  3. git checkout -b test edit LICENSE file git checkout master edit LICENSE file git merge test → will show conflict git status → will show unmerged path edit LICENSE file git commit -a -m&amp;apos;conflict resolved&amp;apos;