KTH Royal Institute of Technology SEMINAR 2-29 March Simone Stefani -

Similar documents
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 Workflows. Sylvain Bouveret, Grégory Mounié, Matthieu Moy

b. Developing multiple versions of a software project in parallel

Beyond git add/commit/push

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

Github/Git Primer. Tyler Hague

The Rock branching strategy is based on the Git Branching Model documented by Vincent Driessen.

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

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

git-flow Documentation

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

Getting the files for the first time...2. Making Changes, Commiting them and Pull Requests:...5. Update your repository from the upstream master...

Lab 08. Command Line and Git

Software Development I

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

Visualizing Git Workflows. A visual guide to 539 workflows

Intro to Github. Jessica Young

Git. Presenter: Haotao (Eric) Lai Contact:

CSC 2700: Scientific Computing

Introduction, Instructions and Conventions

Git for Subversion users

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

Version Control: Gitting Started

Review Version Control Concepts

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

Distributed Version Control

CS 390 Software Engineering Lecture 5 More Git

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

The Old World. Have you ever had to collaborate on a project by

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

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

Tizen/Artik IoT Practice Part 4 Open Source Development

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

Git Basi, workflow e concetti avanzati (pt2)

Git. Charles J. Geyer School of Statistics University of Minnesota. Stat 8054 Lecture Notes

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

Tips on how to set up a GitHub account:

Tutorial 2 GitHub Tutorial

Software Engineering

Version Control. Collaborating with git. Tim Frasier

Laboratorio di Programmazione. Prof. Marco Bertini

Agenda. - Final Project Info. - All things Git. - Make sure to come to lab for Python next week

699DR git/github Tutorial

Use git rm to remove files from workspace

Software configuration management

Welcome! Virtual tutorial will start at 15:00 GMT. Please leave feedback afterwards at:

Git tutorial. Katie Osterried C2SM. October 22, 2015


Python Project Example Documentation

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

How to git with proper etiquette

Git(Lab) Tutorial and Hands-On

MOOSE-Based Application Development on GitLab

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

Versionskontrolle Dario Maggi

Lecture 6 Remotes. Sign in on the attendance sheet!

Using GitHub and SourceTree to work with DITA TC repositories

Version Control. Second level Third level Fourth level Fifth level. - Software Development Project. January 11, 2017

Submitting your Work using GIT

Revision control Advanced git

License. Introduction to Version Control with Git. Local Version Control Systems. Why Use Version Control?

Revision Control. An Introduction Using Git 1/15

chatterbot-weather Documentation

Lab Objective. Lab Assignment. Downloads and Installation

Version Control Systems: Overview

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

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

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

A L A TEX-oriented intro to Git

Python wrapper for Viscosity.app Documentation

AIS Grid School 2015

Git Branching for Agile Teams

Version Control for the 2- Pizza Team: Merge Conflicts (ELLS 9.5) Armando Fox

Git for Newbies. ComMouse Dongyue Studio

Lab 01 How to Survive & Introduction to Git. Web Programming DataLab, CS, NTHU

Using GitHub to Share with SparkFun a

Software Project (Lecture 4): Git & Github

Using Git and GitLab: Your first steps. Maurício

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

FPLLL. Contributing. Martin R. Albrecht 2017/07/06

Introduction to Version Control with Git

RSARTE Git Integration

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

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

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

CS314 Software Engineering Configuration Management

a handful of Git workflows for the agilist steven harman twitter: stevenharman

sainsmart Documentation

django simple pagination Documentation

Version Control Systems (Part 1)

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

Revision control. INF5750/ Lecture 2 (Part I)

Version Control System GIT

Development in code_aster Using Mercurial. Code_Aster, Salome-Meca course material GNU FDL licence (

Version control CSE 403

Python Schema Generator Documentation

ZIP Code to Legislative District Matching via Cicero. Aaron Dennis

Git. CSCI 5828: Foundations of Software Engineering Lecture 02a 08/27/2015

Git. Christoph Matthies Software Engineering II WS 2018/19. Enterprise Platform and Integration Concepts group

Introduction to Git and Github

Transcription:

KTH Royal Institute of Technology SEMINAR 2-29 March 2017 Simone Stefani - sstefani@kth.se

WHAT IS THIS SEMINAR ABOUT Branching Merging and rebasing Git team workflows Pull requests and forks

WHAT IS THIS SEMINAR NOT ABOUT How to setup Git on your computer Git/GitHub Clients with GUI Comparison of workflows

The most important lesson: If you don t know which is the best next move ask your peers for help. You ll learn more and have less problems

PART 3 The Branches

A quick reminder We left PART 1 & 2 with single line of development which is labeled master. This represents the story of the project as a chain of snapshots (commits). It also may have been pushed to a remote hosting service as a remote named origin.

The best idea

Many lines of development One of the best features of Git is the possibility to create lightweight branches allowing for easy and simultaneous development of features. A branch is a line of development that branch off another line of development. The work done on a branch does not affect the other branches. A branch can be thought as a label to the last commit in a line of development.

Create a branch The command git branch <branch-name> creates a new branch with the given name that detaches from the currently selected branch. Initially is hard to visualise the two branches because they contain the same commits. As soon new commits are added to one or the other branch, the two lines of development will appear more clearly. master my-feature $ git branch my-feature

Make a commit on master Switch to feature-branch Make a commit on feature-branch Create two different commits, one on each branch.

my-feature master Now it is possible to see more clearly the two lines of development represented by the branches master and my-feature. The blue circle represents the selected branch.

my-feature master The command git checkout <branch-name> allows to switch to a specified branch. All the commits will now be added to this branch and the working directory is set to represent the current state in the selected branch. my-feature master $ git checkout my-feature

Merging and rebasing

Merge a specific branch into the current branch $ git merge <branch> The command git merge <branch-name> allows to integrate the commits on the specified branch into the current branch. This may happen, for example, when a feature is completed on a branch and needs to be integrated in the main project.

It comes in two flavours: 1. Fast-forward merge 2. Three-way merge At this point is important to consider how the merge of commits may happen. Git will choose between two strategies: fast-forward and three-way merge.

Fast-forward merge my-feature my-feature master master Let s consider the case when my-feature needs to be merged into master. A fast-forward merge will happen when commits have been added on my-feature but not on master. In this case the merge consist in chaining all the new commits from my-feature to the last commit of master. Now the two branches look like the same and contain the same commits.

Three-way merge my-feature master my-feature If different commits have been added on master and my-feature then Git will proceed with a three-way merge. In this case Git will join the content of the two branches and make a new commit containing all the changes introduced in the two lines of development. master

A conflictual story Merge conflicts may happen in case of a three-way merge $ git merge my-feature It may happen that two different commits on different branches change the same file in the same place. In this case Git is not able to tell which version should be kept and it throws a merge CONFLICT. The developer needs to manually inspect the file and decide how the final version should look like. Then commit to complete the merge. Auto-merging hobbit.txt CONFLICT (content): merge conflict in hobbit.txt Automatic merge failed; fix conflicts and then commit the result.

Merge conflicts resolution is an art Conflicts will happen: get used to them! There are many resources to learn how to resolve merge conflicts but the best way it s probably doing it once with someone more experienced. This is one of the situations where it s clearly important to reach for help.

A strategy to avoid conflicts: $ git checkout feature $ git rebase master The command git rebase <target-branch> allows to copy the commits of the current branch and link them to the last commit of the target-branch. In this way if a merge is executed right after the rebase, Git will use the fast-forward strategy.

feature feature master After the executing git rebase master, the feature branch is mounted on top of the last commit in the master branch. Observe that the commits in the feature branch after the rebase are actually copies of the original ones. Now executing a fast-forward merge results to be a trivial operation. master

The golden rule of rebasing: Never use rebase on public branches Rebase should only be used with branches in the local repository. It should never be used with public branches because it would result in re-written history and would create problems to other developers.

feature Rebasing the master branch is always a bad idea especially if the repository has been pushed and other developers are working on the same history. In the picture the master branch has been rebased on top of feature but all the other developers are building their work on top of it. This will generate a large number of conflicts and loss of informations. master master

Fork & Pull Requests

Fork a repository Alice s GitHub repository Bob s GitHub repository Create a copy of someone else repository linking back to the source

Where do I fork? If you are on GitHub visiting someone else repository and you press the button Fork, then GitHub will make a copy of that repository and save it on your account. The two repositories are independent from each other but yours will remember that it was originally copied from the other. From GitHub! And the repository will be copied to my GitHub account

A pull request has nothing to do with the pull command. It is an operation that can be triggered in the GitHub interface with the final goal of asking another developer to integrate the work from a branch of one of your projects into a branch of hers project. Pull request GitHub will then open an interface to ease the code integration procedure. This includes code comparison features, notifications, a system to track issues and bugs and a comment thread to discuss the operation with other developers. Start a discussion with the team about a feature and notify them about any progress

Pull request: in words 1. A developer creates the feature in a dedicated branch in the local repo 2. The developer pushes the branch to a his public GitHub repository 3. The developer files a pull request via GitHub 4. The rest of the team reviews the code, discusses it, and alters it 5. The project maintainer merges the feature into the official repository and closes the pull request

Pull request: in picture Shared GitHub repo (source) Observe that a pull request is an operation that start from a source branch and targets a destination branch (usually on different repositories). Pull requests are especially used as part of a more extensive workflow. source branch destination branch Shared GitHub repo (destination)

PART 4 Team Workflows

When working in a team it is important to establish a common routine to manage Git actions

Workflows

There is no such thing as a right workflow. Choose something that fits your team s needs

Gitflow

Gitflow is a workflow developed by the developer Vincent Driessen as a successful Git branching model shaped after several years of working with Git in teams. The original post can be found at: http://nvie.com/posts/a-successful-git-branching-model/ This model relies on heavy use of branches and it is especially useful in small teams.

A) Set of rules to identify and manage branches B) Set of actions to work in a team on a single project

Branches conventions

master: should always represent the current state of the project in production Production is the technical word to describe the live version of a project. If the project is a website or web service it can refer to the version running on a live server. If the project is an app it is the released version (possibly published on some online store) develop: originating from the master branch, this is the place where development happens

The master branch corresponds to the release history, always reflecting the production state. The commits may be have a tag do describe the version. The develop branch, which is created after the repository initialisation, is used to integrate developed features.

feature: used to add new features to the project Name convention: feature/<name> Originates from: develop Merged into: develop Every new feature should be developed inside its own feature/<name> branch. When the feature is ready it can be merged into develop. No feature should be merged directly into master.

release: used to prepare the code for a release while development on the develop branch continues Name convention: release/<version> Originates from: develop Merged into: first master then develop The release branch is not necessary in every project but can be useful when the development team implements a release workflow. The release branch allows to freeze the software in a stable condition (allowing only further testing and bug fix) while the development may continue on the develop branch.

hotfix: used for severe bugfixes that prevent production from running properly Name convention: hotfix/<name> Originates from: master Merged into: master and develop The hotfix branch is used only when a bug is found in the production code and allows a quick fix that is then integrated both into master and develop.

The big picture

A repository can be created, for example on GitHub, by a team member who has the role of project maintainer. This repository is defined as main (or central) by a team convention (all repositories are equal for Git). Maintainer creates main repository Add all configuration files, README and.gitignore

Using the built-in functionality of GitHub, the other team members fork the central repository thus making a copy of it on their accounts. Developers fork the main repository

Every developer in the team clones her own fork of the repository in order to have a copy on the local machine. When cloning the repository, Git establishes a link setting the developer s own GitHub repository as a remote with name origin. The developer should also add another remote called upstream to link to the main repository (on the maintainer s GitHub account). Developers clone their forked repositories origin: developer s own fork upstream: the main repository

Developers work on their features Make local commits Developers can work independently on their machines making commits in the local repository. For this purpose feature branches should be used.

The developers then push their work (contained in feature branches) from the local repositories to their remote forks using the remote/origin. Developers publish their features Push to their forks (remote/origin)

The project maintainer has the task of integrating the work of the developers into the main repository. In order to do this, each developer opens a pull request from the feature branch on her own fork to the maintainer s develop branch (on the main repository). After the integration is discussed in the pull request thread and all the possible conflicts are solved, the maintainer merges the developers work into the main repository. The project maintainer integrates their features Developers use pull requests

Developers use pull request to ask the maintainer to integrate their features Possible types of pull requests. The most common is from the developer s feature branch to the maintainer s develop branch. In case of hotfix and release branches the pull request should target both develop and master in the maintainer s main repository. own fork main repository

The last step is to synchronize the developers repositories with the main repository. This is needed because only the maintainer s repository reflects the current state of the project after a merge, with the new feature integrated in the develop branch. In order to do this, each developer execute a git pull command (on the local machine) from the main remote repository, available as remote/upstream. Finally the developer can execute a push to remote/origin to keep her own local and remote repositories synchronized. Developers synchronize with the main repository Pull from remote/upstream

Learn more about gitflow at: www.github.com/eschmar/gitflow

Credits All the graphics in this presentation are from Atlassian Getting Right Git guide reachable at: www.atlassian.com/git The content is licensed under a Creative Commons Attribution 2.5 Australia License