SlideShare ist ein Scribd-Unternehmen logo
1 von 54
Downloaden Sie, um offline zu lesen
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

Weitere Àhnliche Inhalte

Was ist angesagt?

An Introduction to Tornado
An Introduction to TornadoAn Introduction to Tornado
An Introduction to Tornado
Gavin Roy
 

Was ist angesagt? (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++
 

Ähnlich wie Practical git for developers

Git training
Git trainingGit training
Git training
eric7master
 
How to use git without rage
How to use git without rageHow to use git without rage
How to use git without rage
Javier Lafora Rey
 

Ähnlich wie 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
 
Git setuplinux
Git setuplinuxGit setuplinux
Git setuplinux
 
GitSetupLinux
GitSetupLinuxGitSetupLinux
GitSetupLinux
 
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
 

Mehr von Wim Godden

Mehr von 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
 

KĂŒrzlich hochgeladen

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

KĂŒrzlich hochgeladen (20)

Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
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
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
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
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
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
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
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
 
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 - 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...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 

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)
  • 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

Hinweis der Redaktion

  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;