Version Control Systems Introduction to Git Dennis Klein - - PowerPoint PPT Presentation

version control systems
SMART_READER_LITE
LIVE PREVIEW

Version Control Systems Introduction to Git Dennis Klein - - PowerPoint PPT Presentation

Version Control Systems Introduction to Git Dennis Klein Scientific IT GSI Darmstadt Panda Computing Workshop 2-7 July 2017 Suranaree University of Technology (SUT), Nakhon Ratchasima Introduction Git Basics Git Workflow Exercises Outline


slide-1
SLIDE 1

Version Control Systems

Introduction to Git Dennis Klein

Scientific IT GSI Darmstadt

Panda Computing Workshop 2-7 July 2017 Suranaree University of Technology (SUT), Nakhon Ratchasima

slide-2
SLIDE 2

Introduction Git Basics Git Workflow Exercises

Outline

1

Introduction

2

Git Basics

3

Git Workflow

4

Exercises

Dennis Klein Version Control Systems Panda Computing Workshop 7/2017 2 / 40

slide-3
SLIDE 3

Introduction Git Basics Git Workflow Exercises

Introduction

1

Introduction What is Version Control? Types of Version Control Systems About Git

Dennis Klein Version Control Systems Panda Computing Workshop 7/2017 3 / 40

slide-4
SLIDE 4

Introduction Git Basics Git Workflow Exercises

What is Version Control?

Definition Version Control is a system that records changes to a set of files in a repository.

Dennis Klein Version Control Systems Panda Computing Workshop 7/2017 4 / 40

slide-5
SLIDE 5

Introduction Git Basics Git Workflow Exercises

What is Version Control?

Definition Version Control is a system that records changes to a set of files in a repository. In the context of this talk we assume the repository is a source code repository.

Dennis Klein Version Control Systems Panda Computing Workshop 7/2017 4 / 40

slide-6
SLIDE 6

Introduction Git Basics Git Workflow Exercises

What is Version Control?

Definition Version Control is a system that records changes to a set of files in a repository. In the context of this talk we assume the repository is a source code repository. It allows to revert files back to a previous state, compare changes over time, keep track of who, when, and why changes are made, reference specific versions of the repository, and more.

Dennis Klein Version Control Systems Panda Computing Workshop 7/2017 4 / 40

slide-7
SLIDE 7

Introduction Git Basics Git Workflow Exercises

Local Version Control System

Dennis Klein Version Control Systems Panda Computing Workshop 7/2017 5 / 40

slide-8
SLIDE 8

Introduction Git Basics Git Workflow Exercises

Local Version Control System

Records patch sets (deltas) for each file on disk. Less error prone than manually copying files to seperate directories. E.g. RCS.

Dennis Klein Version Control Systems Panda Computing Workshop 7/2017 5 / 40

slide-9
SLIDE 9

Introduction Git Basics Git Workflow Exercises

Centralized Version Control System (CVCS)

Dennis Klein Version Control Systems Panda Computing Workshop 7/2017 6 / 40

slide-10
SLIDE 10

Introduction Git Basics Git Workflow Exercises

Centralized Version Control System (CVCS)

Allows collaboration

  • f developers.

Server can facilitate fine-grained access control. E.g. CVS, Subversion, and Perforce.

Dennis Klein Version Control Systems Panda Computing Workshop 7/2017 6 / 40

slide-11
SLIDE 11

Introduction Git Basics Git Workflow Exercises

Distributed Version Control System (DVCS)

Dennis Klein Version Control Systems Panda Computing Workshop 7/2017 7 / 40

slide-12
SLIDE 12

Introduction Git Basics Git Workflow Exercises

Distributed Version Control System (DVCS)

Each computer has a copy of the full history. E.g. Git and Mercurial.

Dennis Klein Version Control Systems Panda Computing Workshop 7/2017 7 / 40

slide-13
SLIDE 13

Introduction Git Basics Git Workflow Exercises

About Git

Written by Linus Torvalds in 2005 Replace commercial DVCS BitKeeper for Linux development Design Goals were

Speed, Simple design, Strong support for non-linear development, Fully distributed, and Scalability for large projects like Linux.

Dennis Klein Version Control Systems Panda Computing Workshop 7/2017 8 / 40

slide-14
SLIDE 14

Introduction Git Basics Git Workflow Exercises

Git Basics

2

Git Basics Configuration Creating a git repo Recording changes Inspecting the history Collaborating Tagging

Dennis Klein Version Control Systems Panda Computing Workshop 7/2017 9 / 40

slide-15
SLIDE 15

Introduction Git Basics Git Workflow Exercises

Configuration

For installation, see https://git-scm.com/downloads Minimal configuration git config

  • -global

user.name "JohnDoe" git config

  • -global

user.email " johndoe@example .com" git config

  • -global

core.editor "nvim" Per user config in ∼/.gitconfig Per repo config in /REPOPATH/.git/config Use Git Attributes for per directory config Check config with git config --list

Dennis Klein Version Control Systems Panda Computing Workshop 7/2017 10 / 40

slide-16
SLIDE 16

Introduction Git Basics Git Workflow Exercises

Advanced Configuration

Recommended configuration git config

  • -global

alias.st "status-bs" git config

  • -global

alias.l "log--pretty=format :\ ’%C(yellow )%h%Cred%ad%Cblue%an%Cgreen%d%Creset%s’\

  • -graph"

Concise status output with git st Compact history view with git l

Dennis Klein Version Control Systems Panda Computing Workshop 7/2017 11 / 40

slide-17
SLIDE 17

Introduction Git Basics Git Workflow Exercises

Init

Initialize a git repo in an existing directory mkdir demo && cd demo git init echo ".swp" > .gitignore git add .gitignore git commit -m "Initialcommit" Initializes .git subdirectory Initial commit No explicit repo name

Dennis Klein Version Control Systems Panda Computing Workshop 7/2017 12 / 40

slide-18
SLIDE 18

Introduction Git Basics Git Workflow Exercises

Clone

Clone an existing repo git clone https :// github.com/ FairRootGroup /FairRoot git clone git@github.com: FairRootGroup /FairRoot git clone git :// github.com/ FairRootGroup /FairRoot git clone /some_fs/FairRoot Clone with different transfer protocols:

HTTP, SSH, GIT, and filesystem

Dennis Klein Version Control Systems Panda Computing Workshop 7/2017 13 / 40

slide-19
SLIDE 19

Introduction Git Basics Git Workflow Exercises

Areas

Dennis Klein Version Control Systems Panda Computing Workshop 7/2017 14 / 40

slide-20
SLIDE 20

Introduction Git Basics Git Workflow Exercises

Lifecycle

Dennis Klein Version Control Systems Panda Computing Workshop 7/2017 15 / 40

slide-21
SLIDE 21

Introduction Git Basics Git Workflow Exercises

Lifecycle

Check current status with git status Add: git add Stage: git add Edit: your favourite editor Remove (tracked): git rm Rename (tracked): git mv Unstage: git reset HEAD Unmodify: git checkout --

Dennis Klein Version Control Systems Panda Computing Workshop 7/2017 15 / 40

slide-22
SLIDE 22

Introduction Git Basics Git Workflow Exercises

Diff

git diff to view unstaged changes git diff --staged (or --cached) to view staged changes

Dennis Klein Version Control Systems Panda Computing Workshop 7/2017 16 / 40

slide-23
SLIDE 23

Introduction Git Basics Git Workflow Exercises

Diff

git diff to view unstaged changes git diff --staged (or --cached) to view staged changes Best practise Before each commit, view git diff --staged to verify and be sure what you are about to commit.

Dennis Klein Version Control Systems Panda Computing Workshop 7/2017 16 / 40

slide-24
SLIDE 24

Introduction Git Basics Git Workflow Exercises

Good commit messages

https://chris.beams.io/posts/git-commit/

1 Separate subject from body with a blank line 2 Limit the subject line to 50 characters 3 Capitalize the subject line 4 Do not end the subject line with a period 5 Use the imperative mood in the subject line 6 Wrap the body at 72 characters 7 Use the body to explain what and why vs. how Dennis Klein Version Control Systems Panda Computing Workshop 7/2017 17 / 40

slide-25
SLIDE 25

Introduction Git Basics Git Workflow Exercises

Good commit messages

https://chris.beams.io/posts/git-commit/

1 Separate subject from body with a blank line 2 Limit the subject line to 50 characters 3 Capitalize the subject line 4 Do not end the subject line with a period 5 Use the imperative mood in the subject line 6 Wrap the body at 72 characters 7 Use the body to explain what and why vs. how

Subject line template If applied, this commit will your subject line here

Dennis Klein Version Control Systems Panda Computing Workshop 7/2017 17 / 40

slide-26
SLIDE 26

Introduction Git Basics Git Workflow Exercises

Good commit messages

https://chris.beams.io/posts/git-commit/

1 Separate subject from body with a blank line 2 Limit the subject line to 50 characters 3 Capitalize the subject line 4 Do not end the subject line with a period 5 Use the imperative mood in the subject line 6 Wrap the body at 72 characters 7 Use the body to explain what and why vs. how

Subject line template If applied, this commit will your subject line here

Dennis Klein Version Control Systems Panda Computing Workshop 7/2017 17 / 40

slide-27
SLIDE 27

Introduction Git Basics Git Workflow Exercises

Committing

Command git commit Opens your editor and lets you type the commit message

Dennis Klein Version Control Systems Panda Computing Workshop 7/2017 18 / 40

slide-28
SLIDE 28

Introduction Git Basics Git Workflow Exercises

Committing

Command git commit Opens your editor and lets you type the commit message Command git commit -m "add a feature" Shortcut for simple commit messages

Dennis Klein Version Control Systems Panda Computing Workshop 7/2017 18 / 40

slide-29
SLIDE 29

Introduction Git Basics Git Workflow Exercises

Committing

Command git commit Opens your editor and lets you type the commit message Command git commit -m "add a feature" Shortcut for simple commit messages Command git commit --amend Recommit the last commit with the current staged changes

Dennis Klein Version Control Systems Panda Computing Workshop 7/2017 18 / 40

slide-30
SLIDE 30

Introduction Git Basics Git Workflow Exercises

Viewing the history

Command git l(og)

Dennis Klein Version Control Systems Panda Computing Workshop 7/2017 19 / 40

slide-31
SLIDE 31

Introduction Git Basics Git Workflow Exercises

Viewing a single commit

Command git show commit hash

Dennis Klein Version Control Systems Panda Computing Workshop 7/2017 20 / 40

slide-32
SLIDE 32

Introduction Git Basics Git Workflow Exercises

Remotes

Definition Remotes are repository-local names which refer to other git repositories.

Dennis Klein Version Control Systems Panda Computing Workshop 7/2017 21 / 40

slide-33
SLIDE 33

Introduction Git Basics Git Workflow Exercises

Remotes

Definition Remotes are repository-local names which refer to other git repositories. Command git remote -v

  • rigin is the default remote after cloning a

repository

Dennis Klein Version Control Systems Panda Computing Workshop 7/2017 21 / 40

slide-34
SLIDE 34

Introduction Git Basics Git Workflow Exercises

Remotes

Definition Remotes are repository-local names which refer to other git repositories. Command git remote -v

  • rigin is the default remote after cloning a

repository Command git remote add url git remote remove name

Dennis Klein Version Control Systems Panda Computing Workshop 7/2017 21 / 40

slide-35
SLIDE 35

Introduction Git Basics Git Workflow Exercises

Fetch and Push

Command git fetch remote Downloads all objects (e.g. commits) and refs (e.g. tags) from the remote repository that you do not have yet. Only deltas are transferred. Command git push remote branch

Dennis Klein Version Control Systems Panda Computing Workshop 7/2017 22 / 40

slide-36
SLIDE 36

Introduction Git Basics Git Workflow Exercises

Commit hash

Definition The commit hash is the result of applying a cryptographic hash function on the metadata and patch set of a git commit. It “uniquely” identifies a git commit and is usually represented as a character string.

Dennis Klein Version Control Systems Panda Computing Workshop 7/2017 23 / 40

slide-37
SLIDE 37

Introduction Git Basics Git Workflow Exercises

Commit hash

Definition The commit hash is the result of applying a cryptographic hash function on the metadata and patch set of a git commit. It “uniquely” identifies a git commit and is usually represented as a character string. Used to reference a certain version of the repository. Easy detection of repository corruption/tampering. No natural order of the commit hash space that follows the commit history. One can use a short version in most cases.

Dennis Klein Version Control Systems Panda Computing Workshop 7/2017 23 / 40

slide-38
SLIDE 38

Introduction Git Basics Git Workflow Exercises

Tagging I

Definition A tag is an arbitrary repository-local name that points to a commit hash.

Dennis Klein Version Control Systems Panda Computing Workshop 7/2017 24 / 40

slide-39
SLIDE 39

Introduction Git Basics Git Workflow Exercises

Tagging I

Definition A tag is an arbitrary repository-local name that points to a commit hash. Used to point out important points in the history. Usually software projects apply their versioning scheme via tags.

Dennis Klein Version Control Systems Panda Computing Workshop 7/2017 24 / 40

slide-40
SLIDE 40

Introduction Git Basics Git Workflow Exercises

Tagging II

Command git tag git tag -l "v1.5.*" List tags.

Dennis Klein Version Control Systems Panda Computing Workshop 7/2017 25 / 40

slide-41
SLIDE 41

Introduction Git Basics Git Workflow Exercises

Tagging II

Command git tag git tag -l "v1.5.*" List tags. Command git tag name [commit hash] git tag -a name -m "Major release" git tag -d name Create and delete lightweight and annotated tags.

Dennis Klein Version Control Systems Panda Computing Workshop 7/2017 25 / 40

slide-42
SLIDE 42

Introduction Git Basics Git Workflow Exercises

Tagging II

Command git tag git tag -l "v1.5.*" List tags. Command git tag name [commit hash] git tag -a name -m "Major release" git tag -d name Create and delete lightweight and annotated tags. Command git push remote tag git push remote --tags Push single or all tags to the remote.

Dennis Klein Version Control Systems Panda Computing Workshop 7/2017 25 / 40

slide-43
SLIDE 43

Introduction Git Basics Git Workflow Exercises

Git Workflow

3

Git Workflow Git Branching Pull Requests FairRoot git workflow Rewriting History

Dennis Klein Version Control Systems Panda Computing Workshop 7/2017 26 / 40

slide-44
SLIDE 44

Introduction Git Basics Git Workflow Exercises

Branches

Definition A branch is similar to a lightweight tag. It is a name pointing to a commit hash. In addition, the pointer tracks (is automatically updated to) the most recent commit.

Dennis Klein Version Control Systems Panda Computing Workshop 7/2017 27 / 40

slide-45
SLIDE 45

Introduction Git Basics Git Workflow Exercises

Branches

Definition A branch is similar to a lightweight tag. It is a name pointing to a commit hash. In addition, the pointer tracks (is automatically updated to) the most recent commit. A built-in ref named HEAD can point to a branch. This branch is then the current branch.

Dennis Klein Version Control Systems Panda Computing Workshop 7/2017 27 / 40

slide-46
SLIDE 46

Introduction Git Basics Git Workflow Exercises

Branches

Definition A branch is similar to a lightweight tag. It is a name pointing to a commit hash. In addition, the pointer tracks (is automatically updated to) the most recent commit. A built-in ref named HEAD can point to a branch. This branch is then the current branch. Command git branch git checkout branch name git checkout -b branch name List branches, set current branch (HEAD), and create a new branch.

Dennis Klein Version Control Systems Panda Computing Workshop 7/2017 27 / 40

slide-47
SLIDE 47

Introduction Git Basics Git Workflow Exercises

Internals I

Dennis Klein Version Control Systems Panda Computing Workshop 7/2017 28 / 40

slide-48
SLIDE 48

Introduction Git Basics Git Workflow Exercises

Internals II

Dennis Klein Version Control Systems Panda Computing Workshop 7/2017 29 / 40

slide-49
SLIDE 49

Introduction Git Basics Git Workflow Exercises

Internals III

Dennis Klein Version Control Systems Panda Computing Workshop 7/2017 30 / 40

slide-50
SLIDE 50

Introduction Git Basics Git Workflow Exercises

Merge fast-forward I

Command git checkout master git merge hotfix

Dennis Klein Version Control Systems Panda Computing Workshop 7/2017 31 / 40

slide-51
SLIDE 51

Introduction Git Basics Git Workflow Exercises

Merge fast-forward II

Command git checkout master git merge hotfix

Dennis Klein Version Control Systems Panda Computing Workshop 7/2017 32 / 40

slide-52
SLIDE 52

Introduction Git Basics Git Workflow Exercises

Merge commit I

Command git checkout master git merge iss53

Dennis Klein Version Control Systems Panda Computing Workshop 7/2017 33 / 40

slide-53
SLIDE 53

Introduction Git Basics Git Workflow Exercises

Merge commit II

Command git checkout master git merge iss53

Dennis Klein Version Control Systems Panda Computing Workshop 7/2017 34 / 40

slide-54
SLIDE 54

Introduction Git Basics Git Workflow Exercises

Pull Requests

Definition A git pull is a shortcut for a fetch and merge.

Dennis Klein Version Control Systems Panda Computing Workshop 7/2017 35 / 40

slide-55
SLIDE 55

Introduction Git Basics Git Workflow Exercises

Pull Requests

Definition A git pull is a shortcut for a fetch and merge. Definition A pull request is the managed process of a git merge (usually via a webbased software tool).

Dennis Klein Version Control Systems Panda Computing Workshop 7/2017 35 / 40

slide-56
SLIDE 56

Introduction Git Basics Git Workflow Exercises

Pull Requests

Definition A git pull is a shortcut for a fetch and merge. Definition A pull request is the managed process of a git merge (usually via a webbased software tool). Asynchronous Distributed Usually combined with a review process

Dennis Klein Version Control Systems Panda Computing Workshop 7/2017 35 / 40

slide-57
SLIDE 57

Introduction Git Basics Git Workflow Exercises

FairRoot git workflow

Dennis Klein Version Control Systems Panda Computing Workshop 7/2017 36 / 40

slide-58
SLIDE 58

Introduction Git Basics Git Workflow Exercises

FairRoot git workflow

https://github.com/AnarManafov/GitWorkflow

Dennis Klein Version Control Systems Panda Computing Workshop 7/2017 36 / 40

slide-59
SLIDE 59

Introduction Git Basics Git Workflow Exercises

Rebase

Golden Rule of rebase “No one shall rebase a shared branch”—Everyone about rebase

Dennis Klein Version Control Systems Panda Computing Workshop 7/2017 37 / 40

slide-60
SLIDE 60

Introduction Git Basics Git Workflow Exercises

Exercises

1 Hosting a git repo on Gitlab.org 2 Resolve merge conflicts 3 Interactive rebase (git rebase -i) Dennis Klein Version Control Systems Panda Computing Workshop 7/2017 38 / 40

slide-61
SLIDE 61

Introduction Git Basics Git Workflow Exercises

Material

https://git-scm.com Progit2 - https://git-scm.com/book man git

Dennis Klein Version Control Systems Panda Computing Workshop 7/2017 39 / 40

slide-62
SLIDE 62

Introduction Git Basics Git Workflow Exercises

Attribution

Pictures in this presentation are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License by http://github.com/progit/progit2. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.

Dennis Klein Version Control Systems Panda Computing Workshop 7/2017 40 / 40