CESSDA Expert Seminar 13 & 14 September 2016 Prague, Czech Republic

Similar documents
Software Development I

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

Git for Newbies. ComMouse Dongyue Studio

Git. Ľubomír Prda. IT4Innovations.

Version Control: Gitting Started

Git. Presenter: Haotao (Eric) Lai Contact:

Git. all meaningful operations can be expressed in terms of the rebase command. -Linus Torvalds, 2015

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

Overview. 1. Install git and create a Github account 2. What is git? 3. How does git work? 4. What is GitHub? 5. Quick example using git and GitHub

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

Version Control with Git

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

What is git? Distributed Version Control System (VCS); Created by Linus Torvalds, to help with Linux development;

GETTING TO KNOW GIT: PART II JUSTIN ELLIOTT PENN STATE UNIVERSITY

Git Introduction CS 400. February 11, 2018

Algorithm Engineering

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

Introduction to distributed version control with git

Tutorial: Getting Started with Git. Introduction to version control Benefits of using Git Basic commands Workflow

GIT. CS 490MT/5555, Spring 2017, Yongjie Zheng

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:

FEEG Applied Programming 3 - Version Control and Git II

GIT FOR SYSTEM ADMINS JUSTIN ELLIOTT PENN STATE UNIVERSITY

Version control with Git.

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

CS 390 Software Engineering Lecture 5 More Git

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

Common Git Commands. Git Crash Course. Teon Banek April 7, Teon Banek (TakeLab) Common Git Commands TakeLab 1 / 18

Gitting things done. Hands-on introduction to git niceties. Jan Urbański Ducksboard

Revision control Advanced git

API RI. Application Programming Interface Reference Implementation. Policies and Procedures Discussion

Revision Control. How can 4. Slides #4 CMPT 276 Dr. B. Fraser. Local Topology Simplified. Git Basics. Revision Control:

Distributed Version Control (with Git)

Fundamentals of Git 1

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

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

Software Revision Control for MASS. Git Basics, Best Practices

Having Fun with Social Coding. Sean Handley. February 25, 2010

FAQ Q: Where/in which branch do I create new code/modify existing code? A: Q: How do I commit new changes? A:

Versioning with git. Moritz August Git/Bash/Python-Course for MPE. Moritz August Versioning with Git

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

Git, the magical version control

Improving Your Life With Git

AIS Grid School 2015

Version Control with GIT

CSE 391 Lecture 9. Version control with Git

Git(Lab) Tutorial and Hands-On

b. Developing multiple versions of a software project in parallel

I m an egotistical bastard, and I name all my projects after myself. First Linux, now git. Linus Torvalds, creator of Linux and Git

What is version control? (discuss) Who has used version control? Favorite VCS? Uses of version control (read)

Github/Git Primer. Tyler Hague

USING GIT FOR AUTOMATION AND COLLABORATION JUSTIN ELLIOTT - MATT HANSEN PENN STATE UNIVERSITY

Beyond git add/commit/push

Push up your code next generation version control with (E)Git

Git for Version Control

Computer Science Design I Version Control with Git

GIT VERSION CONTROL TUTORIAL. William Wu 2014 October 7

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

INET

Version Control System - Git. zswu

Visualizing Git Workflows. A visual guide to 539 workflows

How to be a git. Dominic Mitchell

Source Code Management wih git

A BASIC UNDERSTANDING OF VERSION CONTROL

Version Control Systems (VCS)

Intro to Github. Jessica Young

Lab 08. Command Line and Git

CPSC 491. Lecture 19 & 20: Source Code Version Control. VCS = Version Control Software SCM = Source Code Management

Git better. Collaborative project management using Git and GitHub. Matteo Sostero March 13, Sant Anna School of Advanced Studies

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

Git: (Distributed) Version Control

Introduction to Git. Database Systems DataLab, CS, NTHU Spring, 2018

Getting started with GitHub

Software Project (Lecture 4): Git & Github

DEVNET Introduction to Git. Ashley Roach Principal Engineer Evangelist

Git version control with Eclipse (EGit) Tutorial

1. Which of these Git client commands creates a copy of the repository and a working directory in the client s workspace. (Choose one.

Git for Subversion users

Version Control. Version Control

Lecture 6 Remotes. Sign in on the attendance sheet!

Best Practices. Joaquim Rocha IT-DSS-TD

Introduction to Version Control

Submitting your Work using GIT

Windows. Everywhere else

Version Control with Git

A L A TEX-oriented intro to Git

Introduction to GIT. Jordi Blasco 14 Oct 2011

Software Engineering

Version Control. Second level Third level Fourth level Fifth level. - Software Development Project. January 17, 2018

Git tutorial. Katie Osterried C2SM. October 22, 2015

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. CSCI 5828: Foundations of Software Engineering Lecture 02a 08/27/2015

Assumptions. GIT Commands. OS Commands

Version Control. Version Control

Version Control for Fun and Profit

git-flow Documentation

Introduction, Instructions and Conventions

Working with GIT. Florido Paganelli Lund University MNXB Florido Paganelli MNXB Working with git 1/47

Version Control Systems (Part 1)

Git: Distributed Version Control

Transcription:

CESSDA Expert Seminar 13 & 14 September 2016 Prague, Czech Republic - basics Matthäus Zloch GESIS

Outline for this session Git introduction and some theory Git command basics (plus some little advanced) Goals Understand basic concepts of git What is best practise using git

Not part of this presentation Motivation for version control Using git with other UI-Tools**

Git introduction Git (/ɡɪt/) is a version control system that is used for software development and other version control tasks. As a distributed revision control system it is aimed at speed, data integrity, and support for distributed, non-linear workflows. Git was created by Linus Torvalds in 2005 for development of the Linux kernel, with other kernel developers contributing to its initial development. https://en.wikipedia.org/wiki/git_(software)

Git introduction Git (/ɡɪt/) is a version control system that is used for software development and other version control tasks. As a distributed revision control system it is aimed at speed, data integrity, and support for distributed, non-linear workflows. Git was created by Linus Torvalds in 2005 for development of the Linux kernel, with other kernel developers contributing to its initial development. https://en.wikipedia.org/wiki/git_(software)

Strengths of Git Don t need a server (in the beginning) Operations are local, just sync between remote server You ve got the whole history Every commit, every tag, every branch All repository information is stored in one directory:.git/

Strengths of Git Don t need a server (in the beginning) Operations are local, just sync between remote server You ve got the whole history Every commit, every tag, every branch All repository information is stored in one directory You need a server, to collaborate Allows for following code development workflows

Git Introduction Git is primarily a command line tool UI Tools available execute Git commands in background e.g. Sourcetree, Atlassian https://www.atlassian.com/software/sourcetree IDE s provide a UI

Git Introduction Git is primarily a command line tool UI Tools available execute Git commands in background e.g. Sourcetree, Atlassian https://www.atlassian.com/software/sourcetree IDE s provide a UI Need to understand git "under the hood to profit from UI Tools!

Git hosted https://git.kernel.org/cgit/git/git.git/ Git bash https://git-scm.com/downloads

Git Internal Workflow

Git Internal Workflow 3 levels* Work Working Directory initialize Staging / Index Git Repo / HEAD Stage stage a change Commit commit changes * aka trees

Git Internal Workflow with Remote Working Directory Staging / Index Git Repo / HEAD Git Repo / HEAD 3 + 1 levels Work initialize Stage stage a change Commit commit changes Add remote sync with remote Sync with remote

Git Internal Workflow with Remote Working Directory Staging / Index Git Repo / HEAD Git Repo / HEAD 3 + 1 levels Work checkout project (clone) Stage stage a change Commit commit changes Sync with remote sync with remote

Git Internal Workflow Put local directory under version control $ cd my-project/ $ git init Checkout a remote repository $ cd my-project/ $ git clone username@host:/path/to/repository

Git Internal Workflow Stage local changes $ git add file1.php file2.php $ git add *.php $ git add.

Git Internal Workflow Check status $ git status

Git Internal Workflow Commit some changes (comment in editor) $ git commit With inline comment $ git commit --m "first commit"

Git Internal Workflow Each commit is unique and identified via an SHA1 hash value $ git commit --m "first commit" Hashes can be shortened by the first 7 places

Git Remote Repositories Work in collaboration with others Provide a home for your project Remote Server

Git Remote Repositories Think of remote repositories as adding some frontend services and features for your code Remote Server

Git Remote Repositories They provide features like code analysis automatic building, continuous integration issue tracking, documentation, wiki etc. More important a social platform discuss code pull-/merge-requests

Git Remote Repositories Connect new project with remote repository $ git remote add origin <address> Remote Server https://bitbucket.org https://github.com/ https://any-other.com/

Git Remote Repositories Connect new project with remote repository $ git remote add origin <address> Clone an existing project $ git clone https://mazlo@bitbucket.org/cessda/cessda.guidelines.api.git $ git clone git@bitbucket.org:cessda/cessda.guidelines.api.git

Git Remote Repositories Connect new project with remote repository $ git remote add origin <address> Clone an existing project $ git clone https://mazlo@bitbucket.org/cessda/cessda.guidelines.api.git $ git clone git@bitbucket.org:cessda/cessda.guidelines.api.git Sync local with remote $ git push origin master $ git push github master

Git Remote Repositories Sync remote with local $ git fetch origin $ git merge origin/master In short $ git pull

Git Remote Repositories Can clone/push via HTTPS or SSH (preferred) Provides a secure connection Authenticate against a remote repository

Git Log

Git Log With clone you ve got the whole project history Each commit and 1 st sentence of message per line $ git log --online

Git Log All commits: Matthäus, last 2 weeks, keyword: fix $ git log --author="matthäus" --before="2 weeks ago" --grep="fix"

Git Log Advanced view with all branches $ git log --graph --all --decorate

Git Branching Branches are used to write code which does not affect other code Features Releases Bug fixes Documentation Think of branches as labels or pointers to a specific commit

Git Branching master You ve initialized a repo and done some commits t

Git Branching master Now you create a branch and switch to it (checkout) i-got-it t

Git Branching master On the current branch, you do two more commit i-got-it Only this pointer is updated, master is left behind t

Git Branching master i-got-it You create one more branch, but do not switch i-got-it t

Git Branching master i-got-it On the current branch, you do two more commits you-name-it t

Git Branching Create a branch $ git branch you-name-it List all branches $ git branch

Git Branching Change to another branch $ git checkout you-name-it Create a branch and switch to it $ git checkout b i-got-it $ git status

Git Branching Some Fact Hash: sometimes called a Revision master i-got-it HEAD: think of it as the current branch; May point to a specific Revision you-name-it First comment has no parent A commit may have more than one parent

Git Branching Some Fact master i-got-it you-name-it A commit may have more than one parent?

Git Merging

Git Merging Merging means Join the code, local or remote Update of pointers

Git Merging Merging means Join the code, local or remote Update of pointers Most simple merge is called a "fast-forward"

Git Merging

Git Merging master i-got-it i-got-it you-name-it $ git checkout i-got-it $ git merge you-name-it

Git Merging master i-got-it i-got-it General rule: first checkout the branch (base), then pull-in/merge-in the feature you-name-it $ git checkout i-got-it $ git merge you-name-it

Git Merging i-got-it master you-name-it $ git checkout i-got-it $ git merge you-name-it

Git Merging master i-got-it This one is called a merge-commit you-name-it

Git Merging See merges in the log $ git log --graph --all --decorate

Git Merging master i-got-it you-name-it

Git Merging - Conflicts Can happen, will happen Most often when state of a file is unclear Happens when you merge code Code on local branches git merge Code on local with remote branches git pull

Git Merging Ugly i-got-it master Changes made in the same file, same line you-name-it $ git checkout i-got-it $ git merge you-name-it

Git Merging Ugly Things to do 1. Do not panic 2. Check status to see which files need a resolution $ git status

Git Merging Ugly Things to do 3. Do not panic 4. See the log to see what changes are coming in $ git log..you-name-it

Git Merging Ugly Things to do 3. Resolve conflicts in IDE $ vim file1.php 4. Commit changes $ git commit am "resolve merge conflicts..."

How to prevent merge conflicts Isolate tasks for developers Watch out for line-endings Provide a global settings file for your IDE Provide global git configuration Use clear commit messages Is the change necessary? Fix? Workaround? Check-in as own git project ;) Merge often/asap Do not have long living feature-branches Update your current branch frequently

Git Reset Going back in time

Git Reset Going back in time 3 levels 3 types of reset Working Directory Staging / Index Git Repo / HEAD

Git Reset Going back in time 3 levels 3 types of reset With git reset you can bring a file back to a previous version Working Directory Staging / Index Git Repo / HEAD

Git Reset Going back in time 3 levels 3 types of reset With git reset you can bring a file back to a previous version bring a file back into staging area Working Directory Staging / Index Git Repo / HEAD

Git Reset Going back in time 3 levels 3 types of reset With git reset you can bring a file back to a previous version bring a file back into staging area bring a file back into the working state Working Directory Staging / Index Git Repo / HEAD

Git Reset --hard master i-got-it you-name-it

Git Reset --hard master i-got-it you-name-it $ git checkout you-name-it

Git Reset --hard master i-got-it you-name-it $ git checkout you-name-it $ git reset --hard i-got-it $ git reset --hard abe761f you-name-it

Git Reset --hard master i-got-it you-name-it $ git checkout you-name-it $ git reset --hard i-got-it $ git reset --hard abe761f you-name-it $ git checkout i-got-it

Git Reset --hard master you-name-it i-got-it $ git checkout you-name-it $ git reset --hard i-got-it $ git reset --hard abe761f you-name-it $ git checkout i-got-it $ git reset --hard 87e22a3 $ git reset --hard 87e22a3 you-name-it

Git Reset --soft Go back: Staged state $ git reset --soft dfaa708 Working Directory Staging / Index Git Repo / HEAD $ git status

Git Reset --soft Go back: Staged state $ git reset --soft dfaa708 Working Directory Staging / Index Git Repo / HEAD $ git status Useful when you ve done a commit, but forgot something to add

Git Reset --mixed (default) Go back: Working state $ git add file2.php Working Directory Staging / Index Git Repo / HEAD $ git reset --mixed dfaa708 $ git status

Git Reset Going back in time Warning Please watch out with git reset, you can actually lose you code! git reset is the only way you can really lose code in git

Other useful commands Temporarily ignore changes (no need to commit) $ git stash $ git stash pop Create a patch and send someone via email $ git format-patch master --stdout > fix-news-section.patch $ git appy --check fix-news-section.patch

Other useful commands Check what changes have been made $ git diff $ git diff --cached

Best practises using git

Best Practises Using Git Commit often to see clear history of changes

Best Practises Using Git Commit often to see clear history of changes Commit isolated, logical units of changes One file, but two independent changes $ git add -p $ git commit -m "news -> add buttongroup" $ git add -p $ git commit -m "news, fix -> wrap spans"

Best Practises Using Git A commit message is short and in present tense Suggestion "<context>, <action> -> <short description>", e.g. "news section, fix -> sort by id" A more advanced commit should contain a short title in present tense and a more detailed message below

Best Practises Using Git Create branches (several times a day) Do not hesitate to throw away branches (do not CTRL+Z to revert)

Best Practises Using Git Create branches (several times a day) Do not hesitate to throw away branches (do not CTRL+Z to revert) Do not hesitate to socialise on coding platforms Comment Create issues Discuss code, organise code

Best Practises Using Git Use only one tool to interact with your repository e.g. Sourcetree, Atlassian, https://www.atlassian.com/software/sourcetree Use command completion helpers https://github.com/git/git/blob/master/contrib/completion/gitcompletion.bash

Best Practises Using Git Keep practising!

$ cat $HOME/.gitconfig Thank you

Attributes and Links Git logo by Jason Long http://git-scm.com/downloads/logos, CC BY 3.0, https://commons.wikimedia.org/w/index.php?curid=19329352 Pro Git (free book, also for proginners ) https://www.git-tower.com/learn/git/ebook/en/commandline/advanced-topics/git-flow Git Flow https://www.git-tower.com/learn/git/ebook/en/commandline/advanced-topics/git-flow

in your circle of trust. website: www.cessda.net / twitter: @CESSDA_Data