SlideShare a Scribd company logo
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

More Related Content

PDF
Git::Hooks
PDF
Release with confidence
PDF
SDPHP - Percona Toolkit (It's Basically Magic)
PDF
Information security programming in ruby
PDF
Ruby HTTP clients comparison
PDF
Tornado Web Server Internals
PDF
Groovy Powered Clean Code
PDF
Tornado in Depth
Git::Hooks
Release with confidence
SDPHP - Percona Toolkit (It's Basically Magic)
Information security programming in ruby
Ruby HTTP clients comparison
Tornado Web Server Internals
Groovy Powered Clean Code
Tornado in Depth

What's hot (20)

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

Similar to Practical git for developers (20)

PPTX
11 git version control
PPTX
Git and GitHub
PPTX
Introduction to Git and Github
PPTX
Git and Github workshop GDSC MLRITM
PPTX
Git 101 - An introduction to Version Control using Git
PPTX
An introduction to Git
PPTX
GIT.pptx
PDF
Getting some Git
PPTX
Git workshop
PDF
Git training
PPTX
Git Basics for Software Version Management
PPTX
GitHub Event.pptx
PDF
Git Init (Introduction to Git)
KEY
Let's Git this Party Started: An Introduction to Git and GitHub
PPTX
git & git hub course in information retrieval .pptx
PDF
Git 入门 与 实践
PPTX
github ppt git ppt on git hub to know ab
PDF
Embedded Systems: Lecture 11: Introduction to Git & GitHub (Part 2)
PPTX
PDF
Did you git yet?
11 git version control
Git and GitHub
Introduction to Git and Github
Git and Github workshop GDSC MLRITM
Git 101 - An introduction to Version Control using Git
An introduction to Git
GIT.pptx
Getting some Git
Git workshop
Git training
Git Basics for Software Version Management
GitHub Event.pptx
Git Init (Introduction to Git)
Let's Git this Party Started: An Introduction to Git and GitHub
git & git hub course in information retrieval .pptx
Git 入门 与 实践
github ppt git ppt on git hub to know ab
Embedded Systems: Lecture 11: Introduction to Git & GitHub (Part 2)
Did you git yet?
Ad

More from Wim Godden (20)

PDF
Beyond php - it's not (just) about the code
PDF
Bringing bright ideas to life
PDF
The why and how of moving to php 8
PDF
The why and how of moving to php 7
PDF
My app is secure... I think
PDF
My app is secure... I think
PDF
Building interactivity with websockets
PDF
Bringing bright ideas to life
ODP
Your app lives on the network - networking for web developers
ODP
The why and how of moving to php 7.x
ODP
The why and how of moving to php 7.x
ODP
Beyond php - it's not (just) about the code
ODP
My app is secure... I think
ODP
Building interactivity with websockets
ODP
Your app lives on the network - networking for web developers
ODP
My app is secure... I think
ODP
My app is secure... I think
ODP
The promise of asynchronous php
ODP
My app is secure... I think
ODP
My app is secure... I think
Beyond php - it's not (just) about the code
Bringing bright ideas to life
The why and how of moving to php 8
The why and how of moving to php 7
My app is secure... I think
My app is secure... I think
Building interactivity with websockets
Bringing bright ideas to life
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.x
Beyond php - it's not (just) about the code
My app is secure... I think
Building interactivity with websockets
Your app lives on the network - networking for web developers
My app is secure... I think
My app is secure... I think
The promise of asynchronous php
My app is secure... I think
My app is secure... I think

Recently uploaded (20)

PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Electronic commerce courselecture one. Pdf
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Spectral efficient network and resource selection model in 5G networks
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
KodekX | Application Modernization Development
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
Cloud computing and distributed systems.
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Encapsulation theory and applications.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
NewMind AI Monthly Chronicles - July 2025
Electronic commerce courselecture one. Pdf
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
The AUB Centre for AI in Media Proposal.docx
Spectral efficient network and resource selection model in 5G networks
“AI and Expert System Decision Support & Business Intelligence Systems”
Reach Out and Touch Someone: Haptics and Empathic Computing
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Encapsulation_ Review paper, used for researhc scholars
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
KodekX | Application Modernization Development
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Mobile App Security Testing_ A Comprehensive Guide.pdf
Cloud computing and distributed systems.
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Encapsulation theory and applications.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

Editor's Notes

  • #27: git clone [email_address]:wimg/confoodemo.git
  • #42: * = current brach + = commit is in the branch - = commit is in the branch as a merge
  • #44: 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;