hpln meet git - public 2013

Upload: liran-tal

Post on 14-Apr-2018

221 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/30/2019 HPLN Meet Git - Public 2013

    1/36

    Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

    HP Live Network Meet Git

    Liran Tal

    2013

    Goodbye merge hell, conflicts, and awfully slow svn operations

  • 7/30/2019 HPLN Meet Git - Public 2013

    2/36

    Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

    Motivation

    Already know you that which you need - Yoda

  • 7/30/2019 HPLN Meet Git - Public 2013

    3/36

    Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.3

    Motivation

    Decentralized

    Faster, really. Complete repository clone.

    Developers can work offline, committing all their work locally and pushing to a primary rep

    Redundant and enterprise-ready, if required.

    Lightweight Branches

    Cheap and quick

    Used often, and merged often.

  • 7/30/2019 HPLN Meet Git - Public 2013

    4/36

    Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.4

    Motivation

    Drives for better development methodology

    Gitflow A successful git branching model Code reviews

    Extra curriculum points for reading

    http://nvie.com/posts/a-successful-git-branching-model

  • 7/30/2019 HPLN Meet Git - Public 2013

    5/36

    Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

    Roadmap

    Always in motion, the future is - Yoda

  • 7/30/2019 HPLN Meet Git - Public 2013

    6/36

    Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.6

    Roadmap

    Plans for implementing Git in HP Live Network.

    Using Git,

    better, all of us

    Gradually

    migrating the

    rest of the R&Dteams to Git

    Using Git,

    better

    Working with

    Gitflow

    developmentmethodology

    Using Git

    Preliminary

    evaluation of Git

    Understanding

    Git knowledge

    gap

    Migrating

    backend SVN

    repository to Git

    Using Git in a

    single team (3developers) as

    case study

    Git kick-off

    Motivation for

    Git

    Roadmap

  • 7/30/2019 HPLN Meet Git - Public 2013

    7/36

    Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

    Git Overview

    Try not. Do or do not, there is no try - Yoda

    (heavily based on Git Pro book, @see git-scm.com/book)

  • 7/30/2019 HPLN Meet Git - Public 2013

    8/36

    Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.8

    Git Overview

    CVCS

    SVN operations mostly need to consult a remoteserver repository

    DVCS

    Git operations mostly run on the repository (and later pushed to a

    server)

  • 7/30/2019 HPLN Meet Git - Public 2013

    9/36

    Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.9

    Git Overview

    Changes

    SVN-like data model

    Gnapshots

    Git maintains a snapshot of the d

  • 7/30/2019 HPLN Meet Git - Public 2013

    10/36

    Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.10

    Git Overview

    The Three States

    Modified Staged (the staging area is also known as the index)

    Committed

  • 7/30/2019 HPLN Meet Git - Public 2013

    11/36

    Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.11

    Git Overview

    Git For Work

    IntelliJ In our experience Eclipse with EGIT support is awful

    PHPStorm bundled with Git integration

    Command line Git, my preferred option

    Other Git Tools

    TortoiseGit Gitk

  • 7/30/2019 HPLN Meet Git - Public 2013

    12/36

    Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

    Git Basics

    Try not. Do or do not, there is no try - Yoda

  • 7/30/2019 HPLN Meet Git - Public 2013

    13/36

    Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.13

    Initializing a git repository

    Git Basics

    Starting fresh

    git init

    Working from an existing repository

    git clone

    we know this as svn checkout

  • 7/30/2019 HPLN Meet Git - Public 2013

    14/36

    Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.14

    Adding work

    Git Basics

    Commiting your work

    git add git add -p

    git add -I

    git status

    git commit [file] -m

  • 7/30/2019 HPLN Meet Git - Public 2013

    15/36

    Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.15

    Common commands

    Git Basics

    Commiting your work

    git status git branch

    git diff

    --stagedsee changes between staged to last commit

    git rm

    git mv

    .gitignore git log

    -p view diff

    --stat view a summary of commit file stats

    --pretty=oneline --pretty=full or --pretty=format:%h - %an, %ar : %s

    --graph

    --since=2.weeks

  • 7/30/2019 HPLN Meet Git - Public 2013

    16/36

    Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.16

    Undoing

    Git Basics

    Undoing changes

    git commitamend Commits the staging area again instead of the previous commit

    git reset HEAD

    Unstage a previously staged file

    git checkout --

    Revert local changes to that file

  • 7/30/2019 HPLN Meet Git - Public 2013

    17/36

    Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.17

    Remotes

    Git Basics

    Working with Remotes

    git remote -v Lists remotes configured for this repository

    git remote add

    Adding a remote

    git fetch

    Fetch the changes from the remote repository (not yet merging them)

    git pull

    Fetch and merge changes from the remote repository to the local branch

  • 7/30/2019 HPLN Meet Git - Public 2013

    18/36

    Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.18

    Remotes

    Git Basics

    Working with Remotes

    git push Push your changes to the remote repository

    Pushing is only successful if your local copy is up to date with the remote

    git remote show

    Inspecting the remote for information

    git remote rename

    Renaming a remote

    git remote rm

    Removing a remote

  • 7/30/2019 HPLN Meet Git - Public 2013

    19/36

    Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.19

    Tagging

    Git Basics

    Lightweight and Annotated Tags

    git tag -a v2.0 -m portal release 2.0 [hash] Annotated tags (notice the -a flag) are saved as full Git objects meaning they contain autho

    email, checksum, etc.

    git tag v2.0

    Lightweight tags are just pointers to a commit (dont provide -a, -m or -s)

    git push --tags

    Pushing our tags to the remote repository as they dont get pushed with a plain git push

  • 7/30/2019 HPLN Meet Git - Public 2013

    20/36

    Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

    Git Branches

    Try not. Do or do not, there is no try - Yoda

  • 7/30/2019 HPLN Meet Git - Public 2013

    21/36

    Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.21

    Git Branches

    Overview

    Diverge from the main line of development and continue to do work without messing with tha Expensive process, often requiring you to create a new copy of your source code directory

    Git killer branching

    Incredibly lightweight and prompt

  • 7/30/2019 HPLN Meet Git - Public 2013

    22/36

    Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.22

    Git Branches

    Overview

    Stream-line a development methodology

  • 7/30/2019 HPLN Meet Git - Public 2013

    23/36

    Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.23

    Git Branches

    Starting off

    Starting on a fresh master branch with 3 files: README

    License

    test.rb

    After performing git add && git commit, an example visual

    representation is as such:

  • 7/30/2019 HPLN Meet Git - Public 2013

    24/36

    Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.24

    Git Branches

    Starting off

    With each commit in time a new commit object is created and objects are pointing to parents (

  • 7/30/2019 HPLN Meet Git - Public 2013

    25/36

    Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.25

    Git Branches

    Starting off

    The master branch is simply a pointer that moves forward with each commit you make

  • 7/30/2019 HPLN Meet Git - Public 2013

    26/36

    Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.26

    Git Branches

    Branching off

    Creating new branches means creating new pointers to a certain commit git branch testing

    i

  • 7/30/2019 HPLN Meet Git - Public 2013

    27/36

    Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.27

    Git Branches

    Branching off

    HEAD pointer is used to point to the local branch youre working on now Were still on master cause we only created a new branch (testing) but didnt yet

    switch to it

    Gi B h

  • 7/30/2019 HPLN Meet Git - Public 2013

    28/36

    Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.28

    Git Branches

    Branching off

    HEAD pointer is used to point to the local branch youre working on now Were still on master cause we only created a new branch (testing) but didnt yet

    switch to it

    git checkout testing

    Gi B h

  • 7/30/2019 HPLN Meet Git - Public 2013

    29/36

    Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.29

    Git Branches

    Branching off

    HEAD and testing branch pointers are both updated with each new commit git commit -a -m new file

    Git B h

  • 7/30/2019 HPLN Meet Git - Public 2013

    30/36

    Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.30

    Git Branches

    Branching off

    Going back to our original master branch:

    Updated the HEAD pointer

    Working directory looks different now, representing the state of the master branch

    git checkout master

    Git B h

  • 7/30/2019 HPLN Meet Git - Public 2013

    31/36

    Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.31

    Git Branches

    Diverged road

    Commiting work on the master branch again will diverge and enable us to work on 2 paths

    git commit -a -m another commit

    Git B h

  • 7/30/2019 HPLN Meet Git - Public 2013

    32/36

    Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.32

    Git Branches

    Re-cap

    Branches are simply pointers

    Due to commits data structure it is easy enough to find proper merge base and that process is

    automatic for us

    W b P f Git

  • 7/30/2019 HPLN Meet Git - Public 2013

    33/36

    Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.

    Web Presence for Git

    Gitblit

  • 7/30/2019 HPLN Meet Git - Public 2013

    34/36

    Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.34

    Gitblit

    Gitblit

    Open source Java project for hosting Git repositories

    Includes a web interface for managing and interacting with repositories (attempts to live up to

    promise)

    Gitblit

  • 7/30/2019 HPLN Meet Git - Public 2013

    35/36

    Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.35

    Gitblit

    Gitblit

    Open source Java project for hosting Git repositories

    Includes a web interface for managing and interacting with repositories (attempts to live up to

    promise)

    Includes a Java UI to manage users and their

    certificates

    Feature-full, including repository federation

    and other cool stuff

    Gitblit

  • 7/30/2019 HPLN Meet Git - Public 2013

    36/36

    Copyright 2012 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice.36

    Gitblit

    User Setup

    Configure your git:

    git config --global http.sslverify false

    git config --global http.sslkey /pathto/lirantal.key

    git config --global http.sslcert /pathto/lirantal.pem

    git config --global http.proxy ""

    git config --global user.name "Liran Tal"

    git config --global user.email "[email protected]"

    Youre ready to clone:

    git clone https://gitserver:8443/git/hpln.git