SlideShare uma empresa Scribd logo
1 de 31
Baixar para ler offline
Institute of Computer Science
                                     Chair of Communication Networks
                                               Prof. Dr.-Ing. P. Tran-Gia




              Git Crashkurs
                      Steffen Gebert
steffen punkt gebert ät informatik punkt uni-wuerzburg punkt de
          www3.informatik.uni-wuerzburg.de
Warum Git?
u    Git ist hipp! (u.a. wegen Github)
u    Git ist schnell – vieles geht lokal
u    Git ermöglicht bessere Zusammenarbeit / lokale Abweichungen
u    Arbeit in Branches funktioniert
u    uvm. (als Text sicher nicht soo überzeugend J)




                                                                    2
                                                                    2
                               Steffen Gebert
GIT INTERNALS


                             3
                             3
            Steffen Gebert
Git-Datenstrukturen
 u    Objekte identifiziert über SHA-1 hashes

 u    Blob: zB Inhalt einer Datei
        §  Ohne Dateiname
        §  Ohne Meta-Information




Vieles geklaut von:
http://eagain.net/articles/git-for-computer-scientists/

                                                            4
                                                            4
                                           Steffen Gebert
Git-Datenstrukturen
u    Tree-Objekt verknüpft Meta-Informationen mit Datei- und
      Verzeichnisinhalten
      §  Beschreibt, welche Dateien mit welchen Inhalten existieren




                                                    http://www.slideshare.net/chacon/getting-git
                                                                                       5
                                                                                       5
                                   Steffen Gebert
Git-Datenstrukturen
u    Commit als Pointer auf einen Tree




u    SHA-1 des Commits (u.a.) aus SHA-1 des Trees gebildet
      §  Integrität gewährleistet


                                                              6
                                                              6
                                     Steffen Gebert
Git-Datenstrukturen
u    Branch als Pointer auf einen Commit
      §  Menschen-les/merkbar

u    HEAD als Pointer auf Stand des
      eigenen Working Trees („Checkout“)




                                                  7
                                                  7
                                 Steffen Gebert
Das .git-Verzeichnis
u    Enthält alle Meta- und History-Informationen

           $	
  ls	
  -­‐l	
  .git	
  
           total	
  1028	
                                                                                            Aktueller
           -­‐rw-­‐r-­‐-­‐r-­‐-­‐	
  	
  1	
  st	
  	
  	
  	
  	
  	
  23	
  Feb	
  28	
  14:44	
  HEAD	
             Commit
           drwxr-­‐xr-­‐x	
  	
  2	
  st	
  	
  	
  	
  	
  	
  68	
  Feb	
  28	
  14:43	
  branches	
  
           -­‐rw-­‐r-­‐-­‐r-­‐-­‐	
  	
  1	
  st	
  	
  	
  	
  	
  295	
  Feb	
  28	
  14:44	
  config	
             config 
           -­‐rw-­‐r-­‐-­‐r-­‐-­‐	
  	
  1	
  st	
  	
  	
  	
  	
  	
  73	
  Feb	
  28	
  14:43	
  description	
  
           drwxr-­‐xr-­‐x	
  10	
  st	
  	
  	
  	
  	
  340	
  Feb	
  28	
  14:43	
  hooks	
  
           -­‐rw-­‐r-­‐-­‐r-­‐-­‐	
  	
  1	
  st	
  1019488	
  Feb	
  28	
  14:44	
  index	
  
           drwxr-­‐xr-­‐x	
  	
  3	
  st	
  	
  	
  	
  	
  102	
  Feb	
  28	
  14:43	
  info	
  
           drwxr-­‐xr-­‐x	
  	
  4	
  st	
  	
  	
  	
  	
  136	
  Feb	
  28	
  14:44	
  logs	
                        blobs,
           drwxr-­‐xr-­‐x	
  	
  4	
  st	
  	
  	
  	
  	
  136	
  Feb	
  28	
  14:43	
  objects	
                    commits
           -­‐rw-­‐r-­‐-­‐r-­‐-­‐	
  	
  1	
  st	
  	
  	
  19379	
  Feb	
  28	
  14:44	
  packed-­‐refs	
  
           drwxr-­‐xr-­‐x	
  	
  5	
  st	
  	
  	
  	
  	
  170	
  Feb	
  28	
  14:44	
  refs	
                       branches,
                                                                                                                         tags


                                                                                                                                  8
                                                                                                                                  8
                                                              Steffen Gebert
Das .git-Verzeichnis
                                               Branch:                    „trunk“ bei
u    cat	
  .git/HEAD	
                       master                         SVN
      ref:	
  ref/heads/master	
  
                                                                        Commit
u    cat	
  .git/refs/heads/master	
  	
  
      60117b50a7ad22ba2be2c2b1c1b282bc3649fd02	
  
                                                                                            Tree
u    git	
  cat-­‐file	
  –p	
  60117b50a7ad22ba2be2c2b1c1b282bc3649fd02	
  
      tree	
  0d55691a8e7b252c1a4b04568619fafaaf9ea6e3	
                                   Vorheriger
      parent	
  72cc822724effb930feff2f1b8c1bb5c3651fdde	
                                    Commit
      author	
  Steffen	
  Gebert	
  <steffen.gebert@typo3.org>	
  1362056598	
  +0100	
  
      committer	
  Steffen	
  Gebert	
  <steffen.gebert@typo3.org>	
  1362056598	
  +0100	
  
      	
  
      Here	
  comes	
  the	
  comit	
  message	
  
u    git	
  cat-­‐file	
  –p	
  0d55691a8e7b252c1a4b04568619fafaaf9ea6e3	
  
      100644	
  blob	
  40c7064c2a5f56e6f3129616f11448c87e444ff8	
  README.md	
  
u    git	
  cat-­‐file	
  –p	
  40c7064c2a5f56e6f3129616f11448c87e444ff8	
  
      Willkommen	
  …	
  


                                                                                                 9
                                                                                                 9
                                             Steffen Gebert
GIT BENUTZEN


                                10
                                10
               Steffen Gebert
Lokales Repository anlegen

u    mkdir	
  myrepo	
  

u    cd	
  myrepo	
  

u    git	
  init	
  
      Initialized	
  empty	
  Git	
  repository	
  in	
  myrepo/.git/	
  

u    ls	
  –a	
  
      .	
  	
  ..	
  	
  .git	
  




                                                                            11
                                                                            11
                                      Steffen Gebert
Initiales Setup
u  git	
  config	
  -­‐-­‐global	
  user.name	
  „John	
  Doe“	
  
u  git	
  config	
  -­‐-­‐global	
  user.email	
  „example@uni-­‐wuerzburg.de“	
  


u  Wird wegen -­‐-­‐global in ~/.gitconfig gespeichert
u  Ansonsten in .git/config	
  (repo-spezifisch)


u  git	
  config	
  -­‐-­‐global	
  color.ui	
  auto	
  
u  Show current branch in prompt:
    http://wiki.typo3.org/Tips_and_Tricks_(Git)#Current_branch_in_prompt



                                                                         12
                                                                         12
                                 Steffen Gebert
Datei erstellen
u  echo	
  Willkommen	
  >	
  README.md	
  
u  git	
  status	
  
    	
  
                                                              Immer lesen, was Git uns sagt!
    #	
  On	
  branch	
  master	
                               (hat tendenziell gute Ideen)
    #	
  
    #	
  Initial	
  commit	
  
    #	
                                           zum Index
                                                  hinzufügen
    #	
  Untracked	
  files:	
  
    #	
  	
  	
  (use	
  "git	
  add	
  <file>..."	
  to	
  include	
  in	
  what	
  will	
  
    be	
  committed)	
  
    #	
  
    # 	
  README.md	
  
    nothing	
  added	
  to	
  commit	
  but	
  untracked	
  files	
  present	
  
    (use	
  "git	
  add"	
  to	
  track)	
   Gebert
                                            Steffen
                                                                                           13
                                                                                            13
Datei dem Index hinzufügen
u  git	
  add	
  README.md	
  
    	
  
u  git	
  status	
  
    	
  
    #	
  On	
  branch	
  master	
  
    #	
  
    #	
  Initial	
  commit	
  
    #	
  
    #	
  Changes	
  to	
  be	
  committed:	
  
    #	
  	
  	
  (use	
  "git	
  rm	
  -­‐-­‐cached	
  <file>..."	
  to	
  unstage)	
  
    #	
  
    # 	
  new	
  file:	
  	
  	
  README.md	
  
    #	
  
                                                                                          14
                                                                                          14
                                         Steffen Gebert
Commit erstellen
u  git	
  commit	
  
    	
  
u  export	
  GIT_EDITOR=nano	
  


u  git	
  log	
  
u  git	
  log	
  –p	
  


u    Abkürzung	
  git	
  add	
  +	
  git	
  commit:	
  git	
  commit	
  -­‐a	
  




                                                                                    15
                                                                                    15
                                          Steffen Gebert
Lebenszyklus einer Datei


                                                                  git add




u  untracked (nicht versioniert)
u  unmodified (versioniert, aber nicht verändert)
u  modified (versioniert, verändert, nicht im Stage)
u  staged (versioniert, verändert und im Stage, aber nicht commited)

                                               http://bit.ly/PHPUG_JUN_GITvsSVN
                                                                                  16
                                                                                  16
                              Steffen Gebert
Änderungen Rückgängig machen
u    Uncommittet:
      git	
  checkout	
  -­‐-­‐	
  README.md	
  

u    Add rückgängig machen:
       §  git	
  reset	
  HEAD	
  README.md	
  


u    Generell: Lesen, was git	
  status	
  vorschlägt




                                                           17
                                                           17
                                          Steffen Gebert
BRANCHES


                            18
                            18
           Steffen Gebert
Mit Branches arbeiten
u  Jede Arbeit sollte in einem Feature-Branch erledigt werden
u  git	
  branch	
  myfeature	
  
u  git	
  checkout	
  myfeature	
  
    (oder git	
  checkout	
  -­‐b	
  myfeature)

u  git	
  commit	
  
u  Noch einer (und noch einer)


u  git	
  checkout	
  master	
  
u  git	
  merge	
  myfeature	
  
u  Resultiert in Fast-Forward

                                                                 19
                                                                 19
                                    Steffen Gebert
Merges

u    git	
  checkout	
  -­‐b	
  myfeature2	
  
u    Neue Datei erstellen,	
  git	
  commit	
  
u    git	
  checkout	
  master	
  
u    Neue Datei erstellen,	
  git	
  commit	
  
u    git	
  merge	
  myfeature2	
  
u    Resultiert in Merge commit




                                                        20
                                                        20
                                       Steffen Gebert
ARBEITEN MIT REMOTES


                             21
                             21
            Steffen Gebert
Remote Repositories
u    GIT ist dezentrales Versionskontrollsystem (DVCS)
      §  viele Aktionen ohne Netzwerkkommunikation möglich
      §  es gibt nicht den einen zentralen Server




                                                              fetch / pull


                                                                             push
                                                                             22
                                                                             22
                                 Steffen Gebert
Protokolle
u  file://
u  git://
       §  nur pull, kein push
u    ssh://
       §  push + pull
       §  Repository im normalen Dateisystem
       §  Auth über System
u    http(s):// (SmartHTTP)
       §  push + pull
       §  Auth über Passwort, kann über Credential Helper gecached werden
          https://help.github.com/articles/set-up-git#password-caching

u    Performance-technisch kaum Unterschiede

                                                                         23
                                                                         23
                                                       Steffen Gebert
Repository clonen
     u    git	
  clone	
  ≙	
  svn	
  checkout	
  
     u    git	
  clone	
  https://dike.informatik.uni-­‐wuerzburg.de/git/test/workshop.git	
  

     u    git	
  remote	
  –v	
  
           origin	
  https://dike.informatik.uni-­‐wuerzburg.de/git/test/workshop.git	
  (fetch)	
  
Default
-Name      origin	
  https://dike.informatik.uni-­‐wuerzburg.de/git/test/workshop.git	
  (push)	
  

     u    cat	
  .git/config	
  
           [remote	
  "origin“]	
  
                      	
  fetch	
  =	
  +refs/heads/*:refs/remotes/origin/*	
  
                      	
  url	
  =	
  https://dike.informatik.uni-­‐wuerzburg.de/git/test/workshop.git	
  
     	
  	
  	
  [branch	
  "master"]	
  
                      	
  remote	
  =	
  origin	
  
                      	
  merge	
  =	
  refs/heads/master	
  
                 	
  rebase	
  =	
  true	
  
                                                                                                       24
                                                                                                       24
                                                    Steffen Gebert
Arbeiten mit Remotes
u    git	
  pull	
  = git	
  fetch;	
  git	
  rebase	
  
u    git	
  fetch	
  -­‐-­‐all	
  holt Änderungen aller Remotes
u    git	
  rebase	
  bringt aktuellen Branch vorwärts (auf Stand des
      getrackten Branch)
u    git	
  fetch	
  -­‐-­‐tags	
  holt auch Tags
u    git	
  log	
  
       §  HEAD..origin/master	
  listet Unterschiede von HEAD zu o/m
       §  origin/master..HEAD	
  listet Unterschiede von o/m zu HEAD




                                                                         25
                                                                         25
                                   Steffen Gebert
Pushen
u    Neuen oder andersnamigen Branch pushen:
       §  git	
  push	
  <remote>	
  <branch>	
  
u    Alle lokalen und remote existierenden <branch>	
  nach	
  
      <remote>/<branch> pushen
       §  git	
  push	
  




                                                                   26
                                                                   26
                                         Steffen Gebert
Branches auschecken
u    git	
  branch	
  -­‐a	
  listet alle bekannten Branches auf
u    git	
  checkout	
  <zielbranch> wechselt Branch
u    git	
  checkout	
  -­‐b	
  <new_branch>	
  erstellt Branch basierend auf HEAD	
  
u    Tracking branches                Branch erstellen
       §    Hält „Verbindung“ des lokalen Branches mit remote Branch
       §    git	
  pull	
  weiß sonst nicht, was rebased werden soll / push wohin gepusht
       §    git	
  checkout	
  -­‐b	
  -­‐-­‐track	
  <new_branch>	
  <remote>/<branch>	
  
       §    Nachträglich:	
  git	
  -­‐-­‐set-­‐upstream	
  <branch>	
  <remote>/<branch>
u    Detached head (ausgelöst durch git	
  checkout	
  <remote>/<branch>)
       §  Arbeiten losgelöst von jeglichen Branches


                                                                                  27
                                                                                  27
                                        Steffen Gebert
Remote hinzufügen
                                                                       Name des
                                                                     neuen Remotes

       u     git	
  remote	
  add	
  github	
  https://github.com/lsinfo3/workshop.git	
  
       u     git	
  fetch	
  -­‐-­‐all	
  
              Fetching	
  origin	
  
              Fetching	
  github	
  
       u     git	
  branch	
  -­‐av	
  
         *	
  master	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  a97d21d	
  Explain	
  URLs	
  better	
  
         	
  	
  remotes/github/master	
  a97d21d	
  Explain	
  URLs	
  better	
  
aktueller	
  	
  remotes/origin/HEAD	
  	
  	
  -­‐>	
  origin/master	
  
 Branch 	
  	
  remotes/origin/master	
  a97d21d	
  Explain	
  URLs	
  better	
  




                                                                                                                               28
                                                                                                                               28
                                                                        Steffen Gebert
Eigenen Branch pflegen
u    git	
  checkout	
  –b	
  TYPO3_4-­‐5-­‐rzuw	
  
u    git	
  commit	
  
u    git	
  fetch	
  -­‐-­‐all	
  
u    git	
  log	
  HEAD..typo3org/TYPO3_4-­‐5	
  
u    git	
  log	
  typo3org/TYPO3_4-­‐5..HEAD	
  

u    git	
  merge	
  origin/TYPO3_4-­‐5	
  

u    git	
  rebase	
  ebenfalls möglich, aber nur lokal ungefährlich!

u    git	
  cherry-­‐pick	
  holt Commit(s) aus anderem Branch

                                                                         29
                                                                         29
                                     Steffen Gebert
Git Tipps
u    Essenziell
       §    Shell completion, $PROMPT einrichten (branch anzeigen, show dirty state)
       §    git	
  stash, die Zwischenablage
       §    git	
  alias	
  (git	
  alias.st	
  status)
       §    ~,	
  ~2,	
  ^	
  etc. als Referenzen auf parent commits (git	
  show	
  HEAD~25)
u    Nett
       §  git	
  bisect	
  zum finden „böser“ Commits
       §  git	
  svn	
  zum Arbeiten mit SVN repositories
       §  submodules (wie svn:external)
u    Lesen
       §  „Pro Git“ (http://git-scm.com/book, kostenlos)
       §  AlBlue‘s „Git Tip of the Week“
             http://alblue.bandlem.com/Tag/gtotw/



                                                                                         30
                                                                                         30
                                                     Steffen Gebert
Vorsicht!
u    Niemals tun!
       §  git	
  commit	
  -­‐-­‐amend	
  oder git	
  rebase	
  schon veröffentlichter
           Änderungen
       §  git warnt, push lässt sich mit -­‐-­‐force	
  erzwingen

u    Aufpassen!
       §  Mit git	
  reset	
  -­‐-­‐hard Branch auf anderen SHA setzen
            –  Niemals danach pushen!
            –  Verlorene Commits können nur über git	
  reflog	
  wiedergeholt werden




                                                                                          31
                                                                                          31
                                          Steffen Gebert

Mais conteúdo relacionado

Semelhante a Git Power-Workshop

Semelhante a Git Power-Workshop (8)

Git im team
Git im teamGit im team
Git im team
 
Version management mit Git und Github
Version management mit Git und Github Version management mit Git und Github
Version management mit Git und Github
 
Git
GitGit
Git
 
GIT / SVN
GIT / SVNGIT / SVN
GIT / SVN
 
DWX 2017 - GIT im Leben eines VS Entwicklers
DWX 2017 - GIT im Leben eines VS EntwicklersDWX 2017 - GIT im Leben eines VS Entwicklers
DWX 2017 - GIT im Leben eines VS Entwicklers
 
Einführung Mercurial
Einführung MercurialEinführung Mercurial
Einführung Mercurial
 
Versionskontrolle mit Git
Versionskontrolle mit GitVersionskontrolle mit Git
Versionskontrolle mit Git
 
Sei (k)ein Blödmann und nimm Git!
Sei (k)ein Blödmann und nimm Git!Sei (k)ein Blödmann und nimm Git!
Sei (k)ein Blödmann und nimm Git!
 

Mais de Steffen Gebert

Building an IoT SuperNetwork on top of the AWS Global Infrastructure
Building an IoT SuperNetwork on top of the AWS Global InfrastructureBuilding an IoT SuperNetwork on top of the AWS Global Infrastructure
Building an IoT SuperNetwork on top of the AWS Global InfrastructureSteffen Gebert
 
Wenn selbst ‘erlaube allen Verkehr von 0.0.0.0/0’ nicht hilft - Verbindungspr...
Wenn selbst ‘erlaube allen Verkehr von 0.0.0.0/0’ nicht hilft - Verbindungspr...Wenn selbst ‘erlaube allen Verkehr von 0.0.0.0/0’ nicht hilft - Verbindungspr...
Wenn selbst ‘erlaube allen Verkehr von 0.0.0.0/0’ nicht hilft - Verbindungspr...Steffen Gebert
 
Feature Management Platforms
Feature Management PlatformsFeature Management Platforms
Feature Management PlatformsSteffen Gebert
 
Serverless Networking - How We Provide Cloud-Native Connectivity for IoT Devices
Serverless Networking - How We Provide Cloud-Native Connectivity for IoT DevicesServerless Networking - How We Provide Cloud-Native Connectivity for IoT Devices
Serverless Networking - How We Provide Cloud-Native Connectivity for IoT DevicesSteffen Gebert
 
How our Cloudy Mindsets Approached Physical Routers
How our Cloudy Mindsets Approached Physical RoutersHow our Cloudy Mindsets Approached Physical Routers
How our Cloudy Mindsets Approached Physical RoutersSteffen Gebert
 
Jenkins vs. AWS CodePipeline (AWS User Group Berlin)
Jenkins vs. AWS CodePipeline (AWS User Group Berlin)Jenkins vs. AWS CodePipeline (AWS User Group Berlin)
Jenkins vs. AWS CodePipeline (AWS User Group Berlin)Steffen Gebert
 
Jenkins vs. AWS CodePipeline
Jenkins vs. AWS CodePipelineJenkins vs. AWS CodePipeline
Jenkins vs. AWS CodePipelineSteffen Gebert
 
Monitoring Akka with Kamon 1.0
Monitoring Akka with Kamon 1.0Monitoring Akka with Kamon 1.0
Monitoring Akka with Kamon 1.0Steffen Gebert
 
(Declarative) Jenkins Pipelines
(Declarative) Jenkins Pipelines(Declarative) Jenkins Pipelines
(Declarative) Jenkins PipelinesSteffen Gebert
 
An Open-Source Chef Cookbook CI/CD Implementation Using Jenkins Pipelines
An Open-Source Chef Cookbook CI/CD Implementation Using Jenkins PipelinesAn Open-Source Chef Cookbook CI/CD Implementation Using Jenkins Pipelines
An Open-Source Chef Cookbook CI/CD Implementation Using Jenkins PipelinesSteffen Gebert
 
Let's go HTTPS-only! - More Than Buying a Certificate
Let's go HTTPS-only! - More Than Buying a CertificateLet's go HTTPS-only! - More Than Buying a Certificate
Let's go HTTPS-only! - More Than Buying a CertificateSteffen Gebert
 
Cleaning Up the Dirt of the Nineties - How New Protocols are Modernizing the Web
Cleaning Up the Dirt of the Nineties - How New Protocols are Modernizing the WebCleaning Up the Dirt of the Nineties - How New Protocols are Modernizing the Web
Cleaning Up the Dirt of the Nineties - How New Protocols are Modernizing the WebSteffen Gebert
 
Investigating the Impact of Network Topology on the Processing Times of SDN C...
Investigating the Impact of Network Topology on the Processing Times of SDN C...Investigating the Impact of Network Topology on the Processing Times of SDN C...
Investigating the Impact of Network Topology on the Processing Times of SDN C...Steffen Gebert
 
SDN interfaces and performance analysis of SDN components
SDN interfaces and performance analysis of SDN componentsSDN interfaces and performance analysis of SDN components
SDN interfaces and performance analysis of SDN componentsSteffen Gebert
 
The Development Infrastructure of the TYPO3 Project
The Development Infrastructure of the TYPO3 ProjectThe Development Infrastructure of the TYPO3 Project
The Development Infrastructure of the TYPO3 ProjectSteffen Gebert
 
Der Weg zu TYPO3 CMS 6.0 und Einblicke in die TYPO3-Entwicklung
Der Weg zu TYPO3 CMS 6.0 und Einblicke in die TYPO3-EntwicklungDer Weg zu TYPO3 CMS 6.0 und Einblicke in die TYPO3-Entwicklung
Der Weg zu TYPO3 CMS 6.0 und Einblicke in die TYPO3-EntwicklungSteffen Gebert
 
Official typo3.org infrastructure &
the TYPO3 Server Admin Team
Official typo3.org infrastructure &
the TYPO3 Server Admin TeamOfficial typo3.org infrastructure &
the TYPO3 Server Admin Team
Official typo3.org infrastructure &
the TYPO3 Server Admin TeamSteffen Gebert
 
Neuigkeiten aus dem TYPO3-Projekt
Neuigkeiten aus dem TYPO3-ProjektNeuigkeiten aus dem TYPO3-Projekt
Neuigkeiten aus dem TYPO3-ProjektSteffen Gebert
 

Mais de Steffen Gebert (20)

Building an IoT SuperNetwork on top of the AWS Global Infrastructure
Building an IoT SuperNetwork on top of the AWS Global InfrastructureBuilding an IoT SuperNetwork on top of the AWS Global Infrastructure
Building an IoT SuperNetwork on top of the AWS Global Infrastructure
 
Wenn selbst ‘erlaube allen Verkehr von 0.0.0.0/0’ nicht hilft - Verbindungspr...
Wenn selbst ‘erlaube allen Verkehr von 0.0.0.0/0’ nicht hilft - Verbindungspr...Wenn selbst ‘erlaube allen Verkehr von 0.0.0.0/0’ nicht hilft - Verbindungspr...
Wenn selbst ‘erlaube allen Verkehr von 0.0.0.0/0’ nicht hilft - Verbindungspr...
 
Feature Management Platforms
Feature Management PlatformsFeature Management Platforms
Feature Management Platforms
 
Serverless Networking - How We Provide Cloud-Native Connectivity for IoT Devices
Serverless Networking - How We Provide Cloud-Native Connectivity for IoT DevicesServerless Networking - How We Provide Cloud-Native Connectivity for IoT Devices
Serverless Networking - How We Provide Cloud-Native Connectivity for IoT Devices
 
How our Cloudy Mindsets Approached Physical Routers
How our Cloudy Mindsets Approached Physical RoutersHow our Cloudy Mindsets Approached Physical Routers
How our Cloudy Mindsets Approached Physical Routers
 
Jenkins vs. AWS CodePipeline (AWS User Group Berlin)
Jenkins vs. AWS CodePipeline (AWS User Group Berlin)Jenkins vs. AWS CodePipeline (AWS User Group Berlin)
Jenkins vs. AWS CodePipeline (AWS User Group Berlin)
 
Jenkins vs. AWS CodePipeline
Jenkins vs. AWS CodePipelineJenkins vs. AWS CodePipeline
Jenkins vs. AWS CodePipeline
 
Monitoring Akka with Kamon 1.0
Monitoring Akka with Kamon 1.0Monitoring Akka with Kamon 1.0
Monitoring Akka with Kamon 1.0
 
(Declarative) Jenkins Pipelines
(Declarative) Jenkins Pipelines(Declarative) Jenkins Pipelines
(Declarative) Jenkins Pipelines
 
An Open-Source Chef Cookbook CI/CD Implementation Using Jenkins Pipelines
An Open-Source Chef Cookbook CI/CD Implementation Using Jenkins PipelinesAn Open-Source Chef Cookbook CI/CD Implementation Using Jenkins Pipelines
An Open-Source Chef Cookbook CI/CD Implementation Using Jenkins Pipelines
 
Continuous Delivery
Continuous DeliveryContinuous Delivery
Continuous Delivery
 
Jenkins Pipelines
Jenkins PipelinesJenkins Pipelines
Jenkins Pipelines
 
Let's go HTTPS-only! - More Than Buying a Certificate
Let's go HTTPS-only! - More Than Buying a CertificateLet's go HTTPS-only! - More Than Buying a Certificate
Let's go HTTPS-only! - More Than Buying a Certificate
 
Cleaning Up the Dirt of the Nineties - How New Protocols are Modernizing the Web
Cleaning Up the Dirt of the Nineties - How New Protocols are Modernizing the WebCleaning Up the Dirt of the Nineties - How New Protocols are Modernizing the Web
Cleaning Up the Dirt of the Nineties - How New Protocols are Modernizing the Web
 
Investigating the Impact of Network Topology on the Processing Times of SDN C...
Investigating the Impact of Network Topology on the Processing Times of SDN C...Investigating the Impact of Network Topology on the Processing Times of SDN C...
Investigating the Impact of Network Topology on the Processing Times of SDN C...
 
SDN interfaces and performance analysis of SDN components
SDN interfaces and performance analysis of SDN componentsSDN interfaces and performance analysis of SDN components
SDN interfaces and performance analysis of SDN components
 
The Development Infrastructure of the TYPO3 Project
The Development Infrastructure of the TYPO3 ProjectThe Development Infrastructure of the TYPO3 Project
The Development Infrastructure of the TYPO3 Project
 
Der Weg zu TYPO3 CMS 6.0 und Einblicke in die TYPO3-Entwicklung
Der Weg zu TYPO3 CMS 6.0 und Einblicke in die TYPO3-EntwicklungDer Weg zu TYPO3 CMS 6.0 und Einblicke in die TYPO3-Entwicklung
Der Weg zu TYPO3 CMS 6.0 und Einblicke in die TYPO3-Entwicklung
 
Official typo3.org infrastructure &
the TYPO3 Server Admin Team
Official typo3.org infrastructure &
the TYPO3 Server Admin TeamOfficial typo3.org infrastructure &
the TYPO3 Server Admin Team
Official typo3.org infrastructure &
the TYPO3 Server Admin Team
 
Neuigkeiten aus dem TYPO3-Projekt
Neuigkeiten aus dem TYPO3-ProjektNeuigkeiten aus dem TYPO3-Projekt
Neuigkeiten aus dem TYPO3-Projekt
 

Git Power-Workshop

  • 1. Institute of Computer Science Chair of Communication Networks Prof. Dr.-Ing. P. Tran-Gia Git Crashkurs Steffen Gebert steffen punkt gebert ät informatik punkt uni-wuerzburg punkt de www3.informatik.uni-wuerzburg.de
  • 2. Warum Git? u  Git ist hipp! (u.a. wegen Github) u  Git ist schnell – vieles geht lokal u  Git ermöglicht bessere Zusammenarbeit / lokale Abweichungen u  Arbeit in Branches funktioniert u  uvm. (als Text sicher nicht soo überzeugend J) 2 2 Steffen Gebert
  • 3. GIT INTERNALS 3 3 Steffen Gebert
  • 4. Git-Datenstrukturen u  Objekte identifiziert über SHA-1 hashes u  Blob: zB Inhalt einer Datei §  Ohne Dateiname §  Ohne Meta-Information Vieles geklaut von: http://eagain.net/articles/git-for-computer-scientists/ 4 4 Steffen Gebert
  • 5. Git-Datenstrukturen u  Tree-Objekt verknüpft Meta-Informationen mit Datei- und Verzeichnisinhalten §  Beschreibt, welche Dateien mit welchen Inhalten existieren http://www.slideshare.net/chacon/getting-git 5 5 Steffen Gebert
  • 6. Git-Datenstrukturen u  Commit als Pointer auf einen Tree u  SHA-1 des Commits (u.a.) aus SHA-1 des Trees gebildet §  Integrität gewährleistet 6 6 Steffen Gebert
  • 7. Git-Datenstrukturen u  Branch als Pointer auf einen Commit §  Menschen-les/merkbar u  HEAD als Pointer auf Stand des eigenen Working Trees („Checkout“) 7 7 Steffen Gebert
  • 8. Das .git-Verzeichnis u  Enthält alle Meta- und History-Informationen $  ls  -­‐l  .git   total  1028   Aktueller -­‐rw-­‐r-­‐-­‐r-­‐-­‐    1  st            23  Feb  28  14:44  HEAD   Commit drwxr-­‐xr-­‐x    2  st            68  Feb  28  14:43  branches   -­‐rw-­‐r-­‐-­‐r-­‐-­‐    1  st          295  Feb  28  14:44  config   config  -­‐rw-­‐r-­‐-­‐r-­‐-­‐    1  st            73  Feb  28  14:43  description   drwxr-­‐xr-­‐x  10  st          340  Feb  28  14:43  hooks   -­‐rw-­‐r-­‐-­‐r-­‐-­‐    1  st  1019488  Feb  28  14:44  index   drwxr-­‐xr-­‐x    3  st          102  Feb  28  14:43  info   drwxr-­‐xr-­‐x    4  st          136  Feb  28  14:44  logs   blobs, drwxr-­‐xr-­‐x    4  st          136  Feb  28  14:43  objects   commits -­‐rw-­‐r-­‐-­‐r-­‐-­‐    1  st      19379  Feb  28  14:44  packed-­‐refs   drwxr-­‐xr-­‐x    5  st          170  Feb  28  14:44  refs   branches, tags 8 8 Steffen Gebert
  • 9. Das .git-Verzeichnis Branch: „trunk“ bei u  cat  .git/HEAD   master SVN ref:  ref/heads/master   Commit u  cat  .git/refs/heads/master     60117b50a7ad22ba2be2c2b1c1b282bc3649fd02   Tree u  git  cat-­‐file  –p  60117b50a7ad22ba2be2c2b1c1b282bc3649fd02   tree  0d55691a8e7b252c1a4b04568619fafaaf9ea6e3   Vorheriger parent  72cc822724effb930feff2f1b8c1bb5c3651fdde   Commit author  Steffen  Gebert  <steffen.gebert@typo3.org>  1362056598  +0100   committer  Steffen  Gebert  <steffen.gebert@typo3.org>  1362056598  +0100     Here  comes  the  comit  message   u  git  cat-­‐file  –p  0d55691a8e7b252c1a4b04568619fafaaf9ea6e3   100644  blob  40c7064c2a5f56e6f3129616f11448c87e444ff8  README.md   u  git  cat-­‐file  –p  40c7064c2a5f56e6f3129616f11448c87e444ff8   Willkommen  …   9 9 Steffen Gebert
  • 10. GIT BENUTZEN 10 10 Steffen Gebert
  • 11. Lokales Repository anlegen u  mkdir  myrepo   u  cd  myrepo   u  git  init   Initialized  empty  Git  repository  in  myrepo/.git/   u  ls  –a   .    ..    .git   11 11 Steffen Gebert
  • 12. Initiales Setup u  git  config  -­‐-­‐global  user.name  „John  Doe“   u  git  config  -­‐-­‐global  user.email  „example@uni-­‐wuerzburg.de“   u  Wird wegen -­‐-­‐global in ~/.gitconfig gespeichert u  Ansonsten in .git/config  (repo-spezifisch) u  git  config  -­‐-­‐global  color.ui  auto   u  Show current branch in prompt: http://wiki.typo3.org/Tips_and_Tricks_(Git)#Current_branch_in_prompt 12 12 Steffen Gebert
  • 13. Datei erstellen u  echo  Willkommen  >  README.md   u  git  status     Immer lesen, was Git uns sagt! #  On  branch  master   (hat tendenziell gute Ideen) #   #  Initial  commit   #   zum Index hinzufügen #  Untracked  files:   #      (use  "git  add  <file>..."  to  include  in  what  will   be  committed)   #   #  README.md   nothing  added  to  commit  but  untracked  files  present   (use  "git  add"  to  track)   Gebert Steffen 13 13
  • 14. Datei dem Index hinzufügen u  git  add  README.md     u  git  status     #  On  branch  master   #   #  Initial  commit   #   #  Changes  to  be  committed:   #      (use  "git  rm  -­‐-­‐cached  <file>..."  to  unstage)   #   #  new  file:      README.md   #   14 14 Steffen Gebert
  • 15. Commit erstellen u  git  commit     u  export  GIT_EDITOR=nano   u  git  log   u  git  log  –p   u  Abkürzung  git  add  +  git  commit:  git  commit  -­‐a   15 15 Steffen Gebert
  • 16. Lebenszyklus einer Datei git add u  untracked (nicht versioniert) u  unmodified (versioniert, aber nicht verändert) u  modified (versioniert, verändert, nicht im Stage) u  staged (versioniert, verändert und im Stage, aber nicht commited) http://bit.ly/PHPUG_JUN_GITvsSVN 16 16 Steffen Gebert
  • 17. Änderungen Rückgängig machen u  Uncommittet: git  checkout  -­‐-­‐  README.md   u  Add rückgängig machen: §  git  reset  HEAD  README.md   u  Generell: Lesen, was git  status  vorschlägt 17 17 Steffen Gebert
  • 18. BRANCHES 18 18 Steffen Gebert
  • 19. Mit Branches arbeiten u  Jede Arbeit sollte in einem Feature-Branch erledigt werden u  git  branch  myfeature   u  git  checkout  myfeature   (oder git  checkout  -­‐b  myfeature) u  git  commit   u  Noch einer (und noch einer) u  git  checkout  master   u  git  merge  myfeature   u  Resultiert in Fast-Forward 19 19 Steffen Gebert
  • 20. Merges u  git  checkout  -­‐b  myfeature2   u  Neue Datei erstellen,  git  commit   u  git  checkout  master   u  Neue Datei erstellen,  git  commit   u  git  merge  myfeature2   u  Resultiert in Merge commit 20 20 Steffen Gebert
  • 21. ARBEITEN MIT REMOTES 21 21 Steffen Gebert
  • 22. Remote Repositories u  GIT ist dezentrales Versionskontrollsystem (DVCS) §  viele Aktionen ohne Netzwerkkommunikation möglich §  es gibt nicht den einen zentralen Server fetch / pull push 22 22 Steffen Gebert
  • 23. Protokolle u  file:// u  git:// §  nur pull, kein push u  ssh:// §  push + pull §  Repository im normalen Dateisystem §  Auth über System u  http(s):// (SmartHTTP) §  push + pull §  Auth über Passwort, kann über Credential Helper gecached werden https://help.github.com/articles/set-up-git#password-caching u  Performance-technisch kaum Unterschiede 23 23 Steffen Gebert
  • 24. Repository clonen u  git  clone  ≙  svn  checkout   u  git  clone  https://dike.informatik.uni-­‐wuerzburg.de/git/test/workshop.git   u  git  remote  –v   origin  https://dike.informatik.uni-­‐wuerzburg.de/git/test/workshop.git  (fetch)   Default -Name origin  https://dike.informatik.uni-­‐wuerzburg.de/git/test/workshop.git  (push)   u  cat  .git/config   [remote  "origin“]    fetch  =  +refs/heads/*:refs/remotes/origin/*    url  =  https://dike.informatik.uni-­‐wuerzburg.de/git/test/workshop.git        [branch  "master"]    remote  =  origin    merge  =  refs/heads/master    rebase  =  true   24 24 Steffen Gebert
  • 25. Arbeiten mit Remotes u  git  pull  = git  fetch;  git  rebase   u  git  fetch  -­‐-­‐all  holt Änderungen aller Remotes u  git  rebase  bringt aktuellen Branch vorwärts (auf Stand des getrackten Branch) u  git  fetch  -­‐-­‐tags  holt auch Tags u  git  log   §  HEAD..origin/master  listet Unterschiede von HEAD zu o/m §  origin/master..HEAD  listet Unterschiede von o/m zu HEAD 25 25 Steffen Gebert
  • 26. Pushen u  Neuen oder andersnamigen Branch pushen: §  git  push  <remote>  <branch>   u  Alle lokalen und remote existierenden <branch>  nach   <remote>/<branch> pushen §  git  push   26 26 Steffen Gebert
  • 27. Branches auschecken u  git  branch  -­‐a  listet alle bekannten Branches auf u  git  checkout  <zielbranch> wechselt Branch u  git  checkout  -­‐b  <new_branch>  erstellt Branch basierend auf HEAD   u  Tracking branches Branch erstellen §  Hält „Verbindung“ des lokalen Branches mit remote Branch §  git  pull  weiß sonst nicht, was rebased werden soll / push wohin gepusht §  git  checkout  -­‐b  -­‐-­‐track  <new_branch>  <remote>/<branch>   §  Nachträglich:  git  -­‐-­‐set-­‐upstream  <branch>  <remote>/<branch> u  Detached head (ausgelöst durch git  checkout  <remote>/<branch>) §  Arbeiten losgelöst von jeglichen Branches 27 27 Steffen Gebert
  • 28. Remote hinzufügen Name des neuen Remotes u  git  remote  add  github  https://github.com/lsinfo3/workshop.git   u  git  fetch  -­‐-­‐all   Fetching  origin   Fetching  github   u  git  branch  -­‐av   *  master                                a97d21d  Explain  URLs  better      remotes/github/master  a97d21d  Explain  URLs  better   aktueller    remotes/origin/HEAD      -­‐>  origin/master   Branch    remotes/origin/master  a97d21d  Explain  URLs  better   28 28 Steffen Gebert
  • 29. Eigenen Branch pflegen u  git  checkout  –b  TYPO3_4-­‐5-­‐rzuw   u  git  commit   u  git  fetch  -­‐-­‐all   u  git  log  HEAD..typo3org/TYPO3_4-­‐5   u  git  log  typo3org/TYPO3_4-­‐5..HEAD   u  git  merge  origin/TYPO3_4-­‐5   u  git  rebase  ebenfalls möglich, aber nur lokal ungefährlich! u  git  cherry-­‐pick  holt Commit(s) aus anderem Branch 29 29 Steffen Gebert
  • 30. Git Tipps u  Essenziell §  Shell completion, $PROMPT einrichten (branch anzeigen, show dirty state) §  git  stash, die Zwischenablage §  git  alias  (git  alias.st  status) §  ~,  ~2,  ^  etc. als Referenzen auf parent commits (git  show  HEAD~25) u  Nett §  git  bisect  zum finden „böser“ Commits §  git  svn  zum Arbeiten mit SVN repositories §  submodules (wie svn:external) u  Lesen §  „Pro Git“ (http://git-scm.com/book, kostenlos) §  AlBlue‘s „Git Tip of the Week“ http://alblue.bandlem.com/Tag/gtotw/ 30 30 Steffen Gebert
  • 31. Vorsicht! u  Niemals tun! §  git  commit  -­‐-­‐amend  oder git  rebase  schon veröffentlichter Änderungen §  git warnt, push lässt sich mit -­‐-­‐force  erzwingen u  Aufpassen! §  Mit git  reset  -­‐-­‐hard Branch auf anderen SHA setzen –  Niemals danach pushen! –  Verlorene Commits können nur über git  reflog  wiedergeholt werden 31 31 Steffen Gebert