git the SCM system Jan-Simon Möller training.linuxfoundation.org

Similar documents
Version Control: Gitting Started

GETTING STARTED WITH. Michael Lessard Senior Solutions Architect June 2017

Fundamentals of Git 1

Source Code Management wih git

A BASIC UNDERSTANDING OF VERSION CONTROL

Agenda. Several projects are using GIT Developer(s) Junio Hamano, Linus Torvalds. Qt Stable release (January 31, 2011)

Introduction to GIT. Jordi Blasco 14 Oct 2011

git Version: 2.0b Merge combines trees, and checks out the result Pull does a fetch, then a merge If you only can remember one command:

Creating a Patch. Created by Carl Heymann on 2010 Sep 14 1

Git for Newbies. ComMouse Dongyue Studio

How to version control like a pro: a roadmap to your reproducible & collaborative research

Topics covered. Introduction to Git Git workflows Git key concepts Hands on session Branching models. Git 2

git commit --amend git rebase <base> git reflog git checkout -b Create and check out a new branch named <branch>. Drop the -b

Git and GitHub. Dan Wysocki. February 12, Dan Wysocki Git and GitHub February 12, / 48

Version Control System - Git. zswu

Assumptions. GIT Commands. OS Commands

Computer Science Design I Version Control with Git

Windows. Everywhere else

Version Control Systems

Ingegneria del Software Corso di Laurea in Informatica per il Management (D)VCS. Davide Rossi Dipartimento di Informatica Università di Bologna

Git Guide. Meher Krishna Patel. Created on : Octorber, 2017 Last updated : October, More documents are freely available at PythonDSP

Introduction to Git and Github

Git Tutorial. André Sailer. ILD Technical Meeting April 24, 2017 CERN-EP-LCD. ILD Technical Meeting, Apr 24, 2017 A. Sailer: Git Tutorial 1/36

Git. A Distributed Version Control System. Carlos García Campos

Revision control. INF5750/ Lecture 2 (Part I)

GIT Princípy tvorby softvéru, FMFI UK Jana Kostičová,

2 Initialize a git repository on your machine, add a README file, commit and push

GIT DISTRIBUTED IS THE NEW CENTRALISED

1/20/13 Git tutorial. Git tutorial. Mike Nolta. file:///users/nolta/github/reveal.js/git.html?print-paper#/ 1/31

About SJTUG. SJTU *nix User Group SJTU Joyful Techie User Group

Version Control Systems

Part I Part 1 Version Control Systems (VCSs)

Part I Part 1 Version Control Systems (VCSs)

Git & Github Fundamental by Rajesh Kumar.

Part I Part 1 Version Control Systems (VCSs)

Part I Part 1 Version Control Systems (VCSs)

Part I Part 1 Version Control Systems (VCSs)

Version control with Git.

Θερινό Σχολείο, Ιουλίου git. Αχιλλέας Πιπινέλης. Μονάδα Αριστείας ΕΛ/ΛΑΚ ΤΕΙ Αθήνας

Submitting your Work using GIT

Version Control. Version Control

Revision Control and GIT

Human Version Control

Version Control Systems

Version Control. Version Control. Human Version Control. Version Control Systems

Distributed Version Control (with Git)

Git. SSE2034: System Software Experiment 3, Fall 2018, Jinkyu Jeong

CSE 391 Lecture 9. Version control with Git

So#ware(Project. Lecture'4. Wouter'Swierstra. So#ware(project( (Lecture(4 1

Introduction to Version Control

GIT for companies Mark Struberg, INSO TU Vienna

Working in Teams CS 520 Theory and Practice of Software Engineering Fall 2018

Advanced Operating Systems Control Versioning with GIT. Giuseppe Massari

Version control. what is version control? setting up Git simple command-line usage Git basics

Git. Ľubomír Prda. IT4Innovations.

Git tutorial. Katie Osterried C2SM. October 22, 2015

GUIDE TO MAKE A REAL CONTRIBUTION TO AN OPEN SOURCE PROJECT 1. 1

Introduction to GIT. The distributed SCM

Version Control. Version Control

CS 390 Software Engineering Lecture 5 More Git

How to be a git. Dominic Mitchell

Git for (not-so) dummies

Git - A brief overview

Git Introduction CS 400. February 11, 2018

EECS 470 Lab 4. Version Control System. Friday, 31 st January, 2014

Software Project (Lecture 4): Git & Github

Introduction to Supercomputing

Hg Tutorial. For : COP Object oriented Programming (Using C++) Biswas Parajuli

Introduction to Git. Let us list below some of the best known and most widely used version control systems:

1. Git. Robert Snapp

Git AN INTRODUCTION. Introduction to Git as a version control system: concepts, main features and practical aspects.

Effective Programming Practices for Economists. 7. Version Control, Part II: Git with a Shared Repository

Version Control with Git

Git for Version Control

Git. Presenter: Haotao (Eric) Lai Contact:

TDDC88 Lab 4 Software Configuration Management

Git Tutorial. Version: 0.2. Anders Nilsson April 1, 2014

Index. Alias syntax, 31 Author and commit attributes, 334

INET

GIT tutorial. David Parsons, Soraya Arias, Thomas Calmant November, Preamble 2

Tools for software development:

Chapter 5. Version Control: Git

VCS VERSION CONTROL SYSTEMS

CS 520: VCS and Git. Intermediate Topics Ben Kushigian

CSCI 2132: Software Development. Norbert Zeh. Faculty of Computer Science Dalhousie University. Subversion (and Git) Winter 2019

Git AN INTRODUCTION. Introduction to Git as a version control system: concepts, main features and practical aspects.

Version Control with GIT

6 Git & Modularization

Revision control Advanced git

The Intro. Aaron Bartell Director of IBM i Innovation. Copyright 2015 Aaron Bartell

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Gerrit

Version Control Systems (VCS)

February 2 nd Jean Parpaillon

Introduction to Git and GitHub for Writers Workbook February 23, 2019 Peter Gruenbaum

Git version control with Eclipse (EGit) Tutorial

Git Workflows. Sylvain Bouveret, Grégory Mounié, Matthieu Moy

[Software Development] Development Tools. Davide Balzarotti. Eurecom Sophia Antipolis, France

Programming with Haiku

Introduction to distributed version control with git

Version Control with Git

Transcription:

git the SCM system Jan-Simon Möller training.linuxfoundation.org

Topics What is git (what is a SCM) How to install git How to personalize git How to use git for development

What is git? What is a SCM System?

Source Code Management short: SCM also known as: Version Control component of: Software Configuration Management Used to track: Changes to documents or source-code revisions timestamp author other metadata

1 Trunk, Branch, Tag? Trunks 2 3 The central "golden thread" is called "trunk" Branches can fork from Branches 4 Merges T1 5 Tags the trunk, merged or be 6 discontinued 7 Tags serve as labels/pointers 9 Discontinued development branch (Image: Wikipedia, Revision_controlled_project_visualization.svg, User:Sami Kerola, CC BY-SA 3.0) T2 8 10

SCM system challenges Multiple Users modify code at the same time Even quasi-concurrent edits of the same file Central/Decentralized operation File locking (old approach) Atomic operations (not all SCMs) Merging (from painful to easy)

History and evolution of SCM tools RCS / SCCS Local File CVS, SVN, Client-Server ClearCase, Perforce, Distributed: git, Bazaar, Darcs, arch, Mercurial Distributed

Distributed version control system Open Source created by Linus Torvalds in April 2005 as replacement for the proprietary tool bitkeeper Maintainer since July 2005 Junio Hamano

Design goals Patching in <= 3 seconds!cvs (not like cvs) distributed workfow ( Kernel ) safeguards against corruption

Installation Debian/Ubuntu: apt-get install git CentOS/Fedora/RHEL yum install git dnf install git OpenSUSE zypper install git

Personalize (username/email) git config --global user.name "testuser" git config --global user.email "testuser@example.com"

Typical workfow Clone the repo Do your work Add & commit Amend Push *) we will go through examples next, but wait for the lab part before you try

Clone the repo URL= https://git.opnfv.org/sandbox.git # preparations $~/> export URL="https://git.opnfv.org/sandbox" $~/> mkdir test $~/> cd test # clone the repository $~/test/> git clone $URL or $~/test/> git clone https://git.opnfv.org/sandbox

Do some work Create a new file <yourname>.txt containing Hello World! $~/test/> cd sandbox $~/test/sandbox/> echo 'Hello World!' > jansimon.txt $~/test/sandbox/> git status On branch master Your branch is up to date with 'origin/master'. Untracked files: (use "git add <file>..." to include in what will be committed) jansimon.txt nothing added to commit but untracked files present (use "git add" to track)

State of a file in git

Stage a file for a commit <yourname>.txt $~/test/sandbox/> git add jansimon.txt <yourname>.txt

Stage a file for a commit $~/test/sandbox/> git status On branch master Your branch is up to date with 'origin/master'. Changes to be committed: (use "git reset HEAD <file>..." to unstage) new file: jansimon.txt $~/test/sandbox/>

Commit the file to your local repository $~/test/sandbox/> git commit signoff m Initial commit. [master d7b98bc] Initial commit. 1 file changed, 1 insertion(+) create mode 100644 jansimon.txt $~/test/sandbox/>

a b

Commit Messages Brief description Title: 50 chars max Add new base for common puppet modules Blank line Detailed description Optional: Track modifications (e.g. on ML) Optional: References Sign-off with name and email Intent of this commit is to be a common place where we can contain a common set of puppet modules that installers should leverage when installing/configuring a target system. v3: fixed typos v2: added 80 col linebreaks (url, ml-post, change-id) Signed-off-by: Jan-Simon Möller <dl9pf@gmx.de>

Commit Messages Provide a brief description of the change in the first line. The first line should be limited to 50 characters and should not end with a period. Insert a single blank line after the first line. Provide a detailed description of the change in the following lines. Use breaking paragraphs where needed. Subsequent lines should be wrapped at 72 characters. Use present tense.

Amending Let's adapt the commit with a proper message: $~/test/sandbox/> git commit amend ## THIS WILL OPEN AN EDITOR WINDOW ## ( change with $~/> export EDITOR=/usr/bin/nano ) $~/test/sandbox/>

a b

Push Synchronize a remote repository with your local repository $~/test/sandbox/> # git push <remote> <localbranch>:<remotebranch> $~/test/sandbox/> git push #(using defaults, e.g. remote=origin) or $~/test/sandbox/> git push origin or $~/test/sandbox/> git push origin master:master ATTENTION: Different when using gerrit for code review!

Branches It is easy to create a branch and call checkout. $~/test/sandbox/> git branch * master $~/test/sandbox/> git branch mytopic $~/test/sandbox/> git checkout mytopic $~/test/sandbox/> git branch master * mytopic $~/test/sandbox/>

Branches Git makes creating local branches easy Branches are useful to keep topics separate Branches allow you to track, amend and resubmit changes under review

Changes to an existing (tracked) file Changes need to be staged and committed

Change existing file Lets adapt <yourname>.txt with the current date: $~/test/sandbox/> date >> jansimon.txt $~/test/sandbox/> git diff diff git a/jansimon.txt b/jansimon.txt index 980a0d5..0c57ebe 100644 a/jansimon.txt +++ b/jansimon.txt @@ 1 +1,2 @@ Hello World! +Mon Jan 11 12:10:47 CET 2016 $~/test/sandbox/>

Check the status Let's check with 'git status': $~/test/sandbox/> git status On branch master Your branch is ahead of 'origin/master' by 1 commit. (use "git push" to publish your local commits) Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout <file>..." to discard changes in working directory) modified: jansimon.txt no changes added to commit (use "git add" and/or "git commit a")

Stage file Let's stage the file for the commit: $~/test/sandbox/> git add jansimon.txt $~/test/sandbox/> git status On branch master Your branch is ahead of 'origin/master' by 1 commit. (use "git push" to publish your local commits) Changes to be committed: (use "git reset HEAD <file>..." to unstage) modified: jansimon.txt $~/test/sandbox/>

Commit change Let's commit the change $~/test/sandbox/> git commit s m'add date to <name>.txt' $~/test/sandbox/> git log 1 commit 5af6f74203d0b50f0cb465184985217baf0ee521 Author: Jan Simon Möller <jsmoeller@linuxfoundation.org> Date: Mon Jan 11 12:17:22 2016 +0100 Add date to <name>.txt Signed off by: Jan Simon Möller <jsmoeller@linuxfoundation.org> $~/test/sandbox/>

Switching branches and merging Back to master, add another file,... $~/test/sandbox/> git checkout master $~/test/sandbox/> cat jansimon.txt Hello World! $~/test/sandbox/> date >> killroy was here.txt $~/test/sandbox/> git add killroy was here.txt $~/test/sandbox/> git commit s m'add date to killroy was here.txt'

Switching branches and merging... merge branch mytopic $~/test/sandbox/> git merge mytopic Merge made by the 'recursive' strategy. jansimon.txt 1 + 1 file changed, 1 insertion(+) $~/test/sandbox/> cat jansimon.txt Hello World! Wed Jan 13 12:10:47 CET 2016 $~/test/sandbox/> ls jansimon.txt killroy was here.txt

State of a file in git

Some advanced commands

git init Used to initialize a folder as git repository $~/test/> mkdir newrepo ; cd newrepo $~/test/newrepo/> git init Initialized empty Git repository in /home/user/test/newrepo/.git/ $~/test/newrepo/> tree a L 1.git HEAD branches config description hooks info objects ` refs 5 directories, 3 files

git remote Used to add/change connections to remote repositories $~/test/newrepo/> export URL='https://github.com/dl9pf/example.git' $~/test/newrepo/> export PUSHURL='git@github.com:dl9pf/example.git' $~/test/newrepo/> git remote add origin $URL $~/test/newrepo/> git remote v origin https://github.com/dl9pf/example.git (fetch) origin https://github.com/dl9pf/example.git (push) $~/test/newrepo/> git remote set url push origin $PUSHURL $~/test/newrepo/> git remote v origin https://github.com/dl9pf/example.git (fetch) origin git@github.com:dl9pf/example.git (push)

git fetch git fetch synchronizes the local database with a remote does update the working directory for tracking branches $~/test/newrepo/> git fetch remote: Counting objects: 8, done. remote: Total 8 (delta 0), reused 0 (delta 0), pack reused 8 Unpacking objects: 100% (8/8), done. From https://github.com/dl9pf/example * [new branch] master > origin/master * [new branch] otherbranch > origin/otherbranch * [new branch] yetanotherbranch > origin/yetanotherbranch

git pull Fetch from and integrate with another repository or a local branch $~/test/newrepo/> git pull origin otherbranch From https://github.com/dl9pf/example * branch otherbranch > FETCH_HEAD Updating 18947fa..d320f58 Fast forward other 0 1 file changed, 0 insertions(+), 0 deletions( ) create mode 100644 other

git push Update a remote repository with the objects specified $~/test/newrepo/> git push origin master:yetanotherbranch Total 0 (delta 0), reused 0 (delta 0) To git@github.com:dl9pf/example.git * [new branch] master > yetanotherbranch ## git push <remotename> <sourcebranch>:<destinationbranch>

git rebase Forward-port local commits to the new state of the branch Useful for clean history - BUT no-go if you're the maintainer $~/test/newrepo/> $~/test/newrepo/> git checkout otherbranch $~/test/newrepo/> git rebase master First, rewinding head to replay your work on top of it... Applying: other

Resources http://wiki.opnfv.org/developer/getting_started http://training.linuxfoundation.org free videos introduction-to-git LFD262 - Developing with GIT http://git-scm.com/book/en/v2 More tutorials on the net: rogerdudler.github.io/git-guide marklodato.github.io/visual-git-guide

The labs are integrated with next chapter on 'gerrit'

End 16-01-26