Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Workshop Git

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.

Workshop Git

Workshop Git for Thalia at Radboud University Nijmegen

Avatar for Martijn Brekhof

Martijn Brekhof

March 08, 2016
Tweet

Other Decks in Programming

Transcript

  1. v2a – h01 – 1 Workshop Git • 2­hour workshop

    based on AT Computing's course: • Requirements: ◗ Computer with Git installed ◗ Basic knowledge of Linux/UNIX operating systems and commandline usage • License: Attribution­NonCommercial­NoDerivatives 4.0 International Version control with Git http://www.atcomputing.net/Training/version­control­with­git.en.php © 2016 AT Computing http://creativecommons.org/licenses/by­nc­nd/4.0/ (CC BY­NC­ND 4.0)
  2. v2a – h01 – 2 Different implementations (1) Client file1

    Version Database file2 ... version 2 version 1 version 1 ... Server Client file1 file2 ... Client file1 file2 ... Client/Server Centralized Local Version Database version 2 version 1 version 1 ... © 2016 AT Computing (CC BY­NC­ND 4.0)
  3. v2a – h01 – 3 Different implementations (2) Server Client/Server

    file1 file2 ... Client/Server file1 file2 ... Version Database version 2 version 1 version 1 ... Version Database version 2 version 1 version 1 ... Version Database version 2 version 1 version 1 ... Client/Server Decentralized • Optional: set up one repository as server only © 2016 AT Computing (CC BY­NC­ND 4.0)
  4. v2a – h01 – 4 History of git • September

    30th 1998: Larry McVoy announces BitKeeper • 2002: decision is made to use BitKeeper for kernel development • April 2005: ◗ BitMover announced that it would stop providing a version of BitKeeper free of charge to the community ◗ Git development began as Linus Torvalds could not find any other that met his requirements • June 16th 2005: first kernel released using git (kernel 2.6.12) © 2016 AT Computing (CC BY­NC­ND 4.0)
  5. v2a – h01 – 5 Setting up a repository Command:

    git init [options] [directory] • creates a new git repository • Examples: ◗ creating a new empty repository: ◗ Transforming an existing directory into a Git repository: $ git init my_app $ ls ­a my_app .git $ ls ­a my_app/.git branches config description HEAD hooks info objects refs $ cd my_old_app $ git init $ ls ­a README pingpong.c .git © 2016 AT Computing (CC BY­NC­ND 4.0)
  6. v2a – h01 – 6 Configure your Git environment Command:

    git config [options] <variable> • configures your git installation • Stored in plaintext files ◗ per user (option ­­global): .gitconfig in your homedir. ◗ per repository (option ­­local) (default): <PROJECTDIR>/.git/config ◗ systemwide (option ­­system): /etc/gitconfig • Examples ◗ Define the author name to be used for all commits ◗ Define the author email to be used for all commits $ git config ­­global user.name “John Doe“ $ git config ­­global user.email [email protected] © 2016 AT Computing (CC BY­NC­ND 4.0)
  7. v2a – h01 – 7 Adding files file1 file2 ...

    git repository version 1 version 1 ... file1 file2 ... git repository Current situation Versioned situation Command: git add [options] <file|directory>... • add files to the staging area • Example: add a single file $ git add file1 file2 ... file1 file2 ... git repository file1 file2 ... Staged git add git commit © 2016 AT Computing (CC BY­NC­ND 4.0)
  8. v2a – h01 – 8 Committing the staged snapshot file1

    file2 ... git repository version 1 version 1 ... file1 file2 ... git repository Current situation Versioned situation Command: git commit [options] [file]... • commit the staged snapshot • Example: $ git commit ­m "Initial commit" file1 file2 ... git repository file1 file2 ... Staged git add git commit © 2016 AT Computing (CC BY­NC­ND 4.0)
  9. v2a – h01 – 9 Lifecycle of file status Files

    can be in one of the following four states Untracked Unmodified Modified Staged Add the file Edit the file Add the file Remove the file Commit © 2016 AT Computing (CC BY­NC­ND 4.0)
  10. v2a – h01 – 10 How Git stores versions 1a5c986b

    ca85f079 753c4b26 compressed data compressed data compressed data 100644 blob 1a5c986b .gitignore 100644 blob ca85f079 Makefile 100644 blob 753c4b26 README 040000 tree 264626fa inc 040000 tree a2b93a56 snd 040000 tree bc4c62b7 src 100644 blob c3031628 ... 264626fa 100644 blob 70176522 ... 100644 blob 5c82d8e6 ... a2b93a56 100644 blob dcb49d7c ... 100644 blob c5a9c379 ... bc4c62b7 Tree object Blobs tree 753c4b26 parent 81f92422 author martijn <martijn... committer martijn <mart... Updated versionnumber Commit object 5a4eebb6 753c4b26 © 2016 AT Computing (CC BY­NC­ND 4.0)
  11. v2a – h01 – 11 Visualising the git commit history

    • Each commit object contains a reference to the previous commit (except the first commit) ◗ Because of this visuals of a git history seems to go backwards ◗ HEAD points to last commit object ◗ master is a branch (more on that later) a38f278 3f5e909 81f9242 5a4eebb HEAD oldest newest master © 2016 AT Computing (CC BY­NC­ND 4.0)
  12. v2a – h01 – 12 Creating a branch Command: git

    branch <name> [<commit/tag/branchname>] • List, create, or delete branches • Examples: ◗ Create a new branch from HEAD ◗ Create a new branch from a specific commit 2600f97 HEAD master $ git branch features/explbats features/explbats $ git branch customers/atc 81f9242 81f9242 customers/atc 81f9242 2600f97 HEAD master features/explbats © 2016 AT Computing (CC BY­NC­ND 4.0)
  13. v2a – h01 – 13 Merging a branch Command: git

    merge <branchname> • Join two or more development histories together • Example: ◗ Merge customers/atc on master $ git checkout master Switched to branch 'master' ... $ git merge customers/atc Merge made by the 'recursive' strategy. src/engine.c | 4 ++++ src/main.c | 1 + 2 files changed, 5 insertions(+) 2600f97 HEAD master 81f9242 customers/atc 37f1803 2cc83bc • Performs a 3­way merge • New commit has 2 parents 2600f97 master 81f9242 customers/atc 37f1803 HEAD after merge © 2016 AT Computing (CC BY­NC­ND 4.0)
  14. v2a – h01 – 14 Working together concurrently master ...

    Jack/master master ... Anna/master master ... Jack/master master ... Jack/master $ git fetch Jack $ git merge Jack/master $ git fetch Anna master ... Jack/master Do not push, but pull updates in Anna Jack © 2016 AT Computing (CC BY­NC­ND 4.0)
  15. v2a – h01 – 15 Working together with many developers

    Anna file1 file2 ... Version Database version 2 version 1 version 1 ... Jack file1 file2 ... Version Database version 2 version 1 version 1 ... Bob file1 file2 ... Version Database version 2 version 1 version 1 ... Alice file1 file2 ... Version Database version 2 version 1 version 1 ... © 2016 AT Computing (CC BY­NC­ND 4.0)
  16. v2a – h01 – 16 Problem with pushing updates master

    ... Jack/master master ... Anna/master $ git push Anna master master ... Jack/master • Anna's commit history updated without her knowledge $ git status On branch master nothing to commit, ... $ git status On branch master ... modified: README © 2016 AT Computing (CC BY­NC­ND 4.0)
  17. v2a – h01 – 17 Server Version Database version 2

    version 1 version 1 ... Working with a central remote repository Jack's clone file1 file2 ... Version Database version 2 version 1 version 1 ... Anna's clone file1 file2 ... Version Database version 2 version 1 version 1 ... • Each developer fetches and pushes to the central server © 2016 AT Computing (CC BY­NC­ND 4.0)
  18. v2a – h01 – 18 Fast­forward merge • Your master

    branch • Remote's master branch • After you push remote's master branch 501f497 3c54c20 9a5ac52 6a59afb 501f497 HEAD master 6a59afb HEAD master HEAD master 501f497 3c54c20 9a5ac52 6a59afb © 2016 AT Computing (CC BY­NC­ND 4.0)
  19. v2a – h01 – 19 Working on remote branches •

    Git does not allow you to work directly on remote branches. We therefore need to: 1. Create a new local branch 2. Connect local branch to a remote branch 3. Checkout local branch 4. Develop on local branch 5. Use push to update remote branch • Example • NOTE: Cloning automatically makes your local master track origin/master $ git branch bug/12 origin/bug/12 $ git checkout bug/12 … $ git commit $ git push © 2016 AT Computing (CC BY­NC­ND 4.0)
  20. v2a – h01 – 20 Centralized workflow • Uses a

    single branch (usually master) • Rebase • Merge ... git clone git clone git push git pull ­­rebase OR git pull master Central repository git push © 2016 AT Computing (CC BY­NC­ND 4.0)
  21. v2a – h01 – 21 bug/13 Long­running branches: GitFlow develop

    release­0.9 feature/explodingbats master GitFlow model • Two long running main branches: Master and Develop • Arbitrary amount of support branches v0.1 v0.3 bug/12 v0.2 © 2016 AT Computing (CC BY­NC­ND 4.0)
  22. v2a – h01 – 22 Integration­manager (forking) workflow • One

    central repository serving the “official” project • Each developer has their own public repository • Only maintainer has push access to central repository • Developers ask maintainer to pull in their changes ... Central repository ... Anna's public repository ... Jack's public repository push push push pull pull Developer Developer Maintainer © 2016 AT Computing (CC BY­NC­ND 4.0)
  23. v2a – h01 – 23 Dictator and lieutenants workflow ...

    Central repository ... Lieutenant Developer's public repository Lieutenant Dictator ... ... ... Developer's public repository Developer's public repository Developer's public repository © 2016 AT Computing (CC BY­NC­ND 4.0)