Software Project (Lecture 4): Git & Github

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

Version Control with GIT

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

Introduction to Git and Github

GIT FOR SYSTEM ADMINS JUSTIN ELLIOTT PENN STATE UNIVERSITY

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

GETTING STARTED WITH. Michael Lessard Senior Solutions Architect June 2017

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

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

Version Control: Gitting Started

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

Git Introduction CS 400. February 11, 2018

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

CSE 391 Lecture 9. Version control with Git

Git for Newbies. ComMouse Dongyue Studio

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

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

Git. Presenter: Haotao (Eric) Lai Contact:

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

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

Code Repository. P Blanchfield

Windows. Everywhere else

Revision Control and GIT

Fundamentals of Git 1

CS 390 Software Engineering Lecture 4 - Git

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

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

Lecture 6 Remotes. Sign in on the attendance sheet!

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

Software Development I

Git, the magical version control

Git: Distributed Version Control

DEAD-SIMPLE VERSION CONTROL FOR YOUR TEAM GIT WITH MATTHEW REIDSMA GRAND VALLEY STATE UNIVERSITY

Algorithm Engineering

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

What is Git? What is Git? Version Control. Barry Grant

Git! Fundamentals. IT Pro Roundtable! June 17, 2014!! Justin Elliott! ITS / TLT! Classroom and Lab Computing!! Michael Potter!

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

Version control with Git.

Online Remote Repositories

Software Revision Control for MASS. Git Basics, Best Practices

Computer Science Design I Version Control with Git

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

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

A Brief Git Primer for CS 350

A Brief Introduction to Git. Sylverie Herbert (based on slides by Hautahi Kingi)

Software Revision Control for MASS. Git Installation / Configuration / Use

Submitting your Work using GIT

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

CS 390 Software Engineering Lecture 5 More Git

Version Control. Version Control

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

Using Git to Manage Source RTL

Version Control Systems

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

Assumptions. GIT Commands. OS Commands

Revision control. INF5750/ Lecture 2 (Part I)

Git for Subversion users

Version Control with Git

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

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

Technology Background Development environment, Skeleton and Libraries

Git Branching. Chapter What a Branch Is

Introduction to Version Control using Git

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

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

VCS VERSION CONTROL SYSTEMS

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

Outline. Introduction to Version Control Systems Origins of Git Git terminology & concepts Basic Git commands Branches in Git Git over the network

LAB MANUAL GIT BY PRATIK JAIN. To start with git bash, we need to authenticate ourselves so that for every commit, git can use this information.

Outline. Introduction to Version Control Systems Origins of Git Git terminology & concepts Basic Git commands Branches in Git Git over the network

Midterm Next Week. Last year s midterm (which didn t include remotes):

A BASIC UNDERSTANDING OF VERSION CONTROL

Object Oriented Programming. Week 1 Part 2 Git and egit


Git: Distributed Version Control

Technology Background Development environment, Skeleton and Libraries

Outline. Version Control System (VCS) basics Git terminology & concepts Basic Git commands Branches in Git Git over the network (time permitting)

Introduction to Version Control with Git and GitHub

Using git to download and update BOUT++

Improving Your Life With Git

Git tutorial. Katie Osterried C2SM. October 22, 2015

Lab Exercise Git: A distributed version control system

Project Management. Overview

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

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

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

Git for (not-so) dummies

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

Version control. with git and GitHub. Karl Broman. Biostatistics & Medical Informatics, UW Madison

Lecture 01 - Working with Linux Servers and Git

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 Princípy tvorby softvéru, FMFI UK Jana Kostičová,

AIS Grid School 2015

Barry Grant

CS 320 Introduction to Software Engineering Spring February 06, 2017

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

Version Control System - Git. zswu

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

2/8/18. Overview. Project Management. The First Law. What is Project Management? What Are These Changes? Software Configuration Management (SCM)

Transcription:

Software Project (Lecture 4): Git & Github Wouter Swierstra, Atze Dijkstra Feb 2016 Wouter Swierstra, Atze Dijkstra Software Project (Lecture 4): Git & Github Feb 2016 1 / 45

Wouter Swierstra, Atze Dijkstra Software Project (Lecture 4): Git & Github Feb 2016 2 / 45

Last time Risks Software architecture Wouter Swierstra, Atze Dijkstra Software Project (Lecture 4): Git & Github Feb 2016 3 / 45

Working effectively with git and GitHub. Wouter Swierstra, Atze Dijkstra Software Project (Lecture 4): Git & Github Feb 2016 4 / 45

Collaborative software development You have two weeks to finish your user stories. And need to give a demo at the end. How can you develop different stories in parallel without breaking your working prototype? Wouter Swierstra, Atze Dijkstra Software Project (Lecture 4): Git & Github Feb 2016 5 / 45

Version control Wouter Swierstra, Atze Dijkstra Software Project (Lecture 4): Git & Github Feb 2016 6 / 45

What is git? A popular, powerful distributed file version control system It is free and obtainable from git-scm.com Originally developed to manage the Linux kernel An estimated 27 percent of professional developers uses Git (May 12). Wouter Swierstra, Atze Dijkstra Software Project (Lecture 4): Git & Github Feb 2016 7 / 45

Getting to grips with git Git is a very powerful tool with many different features. The user interface takes some getting used to... When used correctly, it can be extremely effective. If you screw up, there is usually a way to undo your changes. Use StackOverflow! Wouter Swierstra, Atze Dijkstra Software Project (Lecture 4): Git & Github Feb 2016 8 / 45

Starting a new repo $ git init Initialized empty Git repository in.git/ Add the README.md file to the repository $ git add README.md Commit the changes you made to README.md $ git commit -m "Added README.md" Wouter Swierstra, Atze Dijkstra Software Project (Lecture 4): Git & Github Feb 2016 9 / 45

Cloning an existing repository To get your hands on a copy of an existing repository use: $ git clone git://github.com/wouter-swierstra/softwareproject Note that git clone supports several different protocols, including SSH. Wouter Swierstra, Atze Dijkstra Software Project (Lecture 4): Git & Github Feb 2016 10 / 45

Git vs Svn Git is a distributed version control system: a copy of a repository can share changes with any other copy. almost all commands operate on your local copy sharing changes with others happens in two steps: commiting your changes locally pushing these changes to a remote server Wouter Swierstra, Atze Dijkstra Software Project (Lecture 4): Git & Github Feb 2016 11 / 45

Git terminology Figure 1: Picture from Scott Chacon s Pro-Git. Untracked not in the repository Unmodified tracked, but not modified Modified tracked and modified Staged modified and to be included in the next commit Wouter Swierstra, Atze Dijkstra Software Project (Lecture 4): Git & Github Feb 2016 12 / 45

Git status $ git status # On branch master nothing to commit (working directory clean) $ emacs 04-slides.md $ git status # On branch master # Untracked files: # (use "git add <file>..." to include in what will be commit # # 04-slides.md So we need to add 04-slides.md Wouter Swierstra, Atze Dijkstra Software Project (Lecture 4): Git & Github Feb 2016 13 / 45

Adding new files $ git add 04-slides.md $ git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # new file: 04-slides.md Wouter Swierstra, Atze Dijkstra Software Project (Lecture 4): Git & Github Feb 2016 14 / 45

Staging modified files Similarly, we can stage modified files using git add. $ emacs README.md $ git add README.md # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # new file: 04-slides.md # modified: README.md Git gives you control over which files to include in a single commit. Wouter Swierstra, Atze Dijkstra Software Project (Lecture 4): Git & Github Feb 2016 15 / 45

Pro-tip:.gitignore to minimize noise Generated binaries, documentation, and so forth are not under version control, but keep showing up when you run git status. You can have a.gitignore file, listing the files, directories, and patterns that you want git to ignore: $ cat.gitignore *.pdf.ds_store build/ Wouter Swierstra, Atze Dijkstra Software Project (Lecture 4): Git & Github Feb 2016 16 / 45

Committing your changes The git commit command commits all the staged changes. $ git commit -m "Added 04-slides.md; updated README.md" [master 76d15ab] Added 04-slides.md; updated README.md 1 files changed, 1 insertions(+), 0 deletions(-) create mode 100644 04-slides.md These changes are recorded locally but not yet shared with others. Wouter Swierstra, Atze Dijkstra Software Project (Lecture 4): Git & Github Feb 2016 17 / 45

Not mentioned git mv to rename files, without losing their history git rm to remove files from the repository git commit -a to record all your changes to tracked files git log to get an overview of recent changes git reset to undo changes Wouter Swierstra, Atze Dijkstra Software Project (Lecture 4): Git & Github Feb 2016 18 / 45

Sharing your changes All these commands operate on your local copy of the repository. Nothing is shared with others yet. git pull pulls in changes from some other repository git push pushes your changes to another repository These commands communicate with remote repositories. Wouter Swierstra, Atze Dijkstra Software Project (Lecture 4): Git & Github Feb 2016 19 / 45

Basic usage: git push $ git clone git://github.com/wouter-swierstra/softwareproject... $ emacs 04-slides.md $ git commit -am "Updated slides on git"... $ git push Counting objects: 9, done. Delta compression using up to 2 threads. Compressing objects: 100% (5/5), done. Writing objects: 100% (5/5), 3.37 KiB, done. Total 5 (delta 4), reused 0 (delta 0) To git@github.com:wouter-swierstra/softwareproject.git 6040584..9b40f60 master -> master Git s user interface can be a bit noisy... Wouter Swierstra, Atze Dijkstra Software Project (Lecture 4): Git & Github Feb 2016 20 / 45

Basic usage: git pull $ git pull remote: Counting objects: 15, done. remote: Compressing objects: 100% (15/15), done. remote: Total 15 (delta 4), reused 1 (delta 0) Unpacking objects: 100% (15/15), done. From github.com:wouter-swierstra/softwareproject 6abc078..08fac51 master -> origin/master Updating 6abc078..08fac51 This pulls in any new changes from the remote repository Wouter Swierstra, Atze Dijkstra Software Project (Lecture 4): Git & Github Feb 2016 21 / 45

Showing remote repositories $ git clone git://github.com/wouter-swierstra/softwareproject... $ git remote -v origin git://github.com/wouter-swierstra/softwareproject (pus origin git://github.com/wouter-swierstra/softwareproject (fet You can add new remote branches using git remote add remotename git://github.com/user/repository.git Feel free to choose your own meaningful remotename Wouter Swierstra, Atze Dijkstra Software Project (Lecture 4): Git & Github Feb 2016 22 / 45

Recap This covers the basic interactions necessary to mimic subversion. Git makes it very easy to work on different versions of your software. You can create new branches, switch between branches, or merge branches quickly and easily. Using branches effectively can drastically improve collaborative development. Wouter Swierstra, Atze Dijkstra Software Project (Lecture 4): Git & Github Feb 2016 23 / 45

Branching In git, a branch is effectively a pointer to some repository state. You can add new changes to any specific branch, which may cause development lines to diverge. Branches may be merged, aggregating changes made in different development lines. Figure 2: Branching Wouter Swierstra, Atze Dijkstra Software Project (Lecture 4): Git & Github Feb 2016 24 / 45

Creating and switching branches $ git branch iss53 $ git branch iss53 * master $ git checkout iss53 $ git branch * iss53 master Wouter Swierstra, Atze Dijkstra Software Project (Lecture 4): Git & Github Feb 2016 25 / 45

Figure 3: Master and branch Wouter Swierstra, Atze Dijkstra Software Project (Lecture 4): Git & Github Feb 2016 26 / 45

Diverging branches If I m in the iss53 branch, I can make changes without effecting the master branch. $ emacs README.md $ git commit -am "Working on #53" Wouter Swierstra, Atze Dijkstra Software Project (Lecture 4): Git & Github Feb 2016 27 / 45

Figure 4: Diverging branch Wouter Swierstra, Atze Dijkstra Software Project (Lecture 4): Git & Github Feb 2016 28 / 45

Even more branches $ git checkout master $ git branch hotfix $ git checkout hotfix $ emacs README.md $ git commit -am "Hotfix in README.md" Wouter Swierstra, Atze Dijkstra Software Project (Lecture 4): Git & Github Feb 2016 29 / 45

Figure 5: More branches How to get the changes to the hotfix branch back into master? Wouter Swierstra, Atze Dijkstra Software Project (Lecture 4): Git & Github Feb 2016 30 / 45

Git merge $ git checkout master $ git merge hotfix Updating f42c576..3a0874c Fast-forward README.md 2 ++ 1 file changed, 2 insertions(+) Wouter Swierstra, Atze Dijkstra Software Project (Lecture 4): Git & Github Feb 2016 31 / 45

Figure 6: Fast forward merge From this point on, continue development in the iss53 branch until it is ready to be merged with the master branch. Wouter Swierstra, Atze Dijkstra Software Project (Lecture 4): Git & Github Feb 2016 32 / 45

Not covered Using git branch -d to delete branches Working with remote branches How git pull uses branches under the hood. More advanced branching commands Wouter Swierstra, Atze Dijkstra Software Project (Lecture 4): Git & Github Feb 2016 33 / 45

The real challenge This covers the very basic git operations. You can now collaborate on a single codebase. But collaborating effectively is not easy. Wouter Swierstra, Atze Dijkstra Software Project (Lecture 4): Git & Github Feb 2016 34 / 45

Golden rules 1 The master branch may only contain code that is tested, reviewed and ready to be released. 2 Only commit code that compiles, even in experimental branches. 3 New user stories start in a fresh branch; no such branch lives more than three iterations, before being merged. 4 Create pull requests for every new branch. Only merge your changes if everyone is happy, the code is tested and reviewed. Wouter Swierstra, Atze Dijkstra Software Project (Lecture 4): Git & Github Feb 2016 35 / 45

1 The master branch is ready for release The master branch serves a single purpose: it represents the current stable version of development If I walk into your office at any point in time, you should be able to demo the master branch. The code should be so good, that you d be happy to release it, even if it lacks functionality. Wouter Swierstra, Atze Dijkstra Software Project (Lecture 4): Git & Github Feb 2016 36 / 45

2 Only commit code that compiles Figure 7: Build break consequences Wouter Swierstra, Atze Dijkstra Software Project (Lecture 4): Git & Github Feb 2016 37 / 45

2 Only commit code that compiles Breaking the build is the cardinal sin of collaborative development. This blocks the entire development team, until you fix the issue. Compile and run your regression tests before committing don t make other people clean up your mess. Wouter Swierstra, Atze Dijkstra Software Project (Lecture 4): Git & Github Feb 2016 38 / 45

3 New stories start in a new branch The master branch is the stable development release. Unfinished features are never developed on the master branch directly. Instead, every iteration starts with several new branches. Once new features are tested, reviewed and ready, they can be merged back into master. Wouter Swierstra, Atze Dijkstra Software Project (Lecture 4): Git & Github Feb 2016 39 / 45

4 Create pull requests In principle, you can manage branches from the commandline. If you choose to host your code on GitHub you have some additional features that can help collaboration: Issue tracker (which can be used for your product backlog) Wiki for tracking documentation, discussions, or meeting notes. GUI for creating and merging branches Pull request = Code + Issue + Discussion Wouter Swierstra, Atze Dijkstra Software Project (Lecture 4): Git & Github Feb 2016 40 / 45

Github Demo Wouter Swierstra, Atze Dijkstra Software Project (Lecture 4): Git & Github Feb 2016 41 / 45

Golden rules 1 The master branch may only contain code that is tested, reviewed and ready to be released. 2 Only commit code that compiles, even in experimental branches. 3 New user stories start in a fresh branch; no such branch lives more than three iterations, before being merged. 4 Create pull requests for every new branch. Only merge your changes if everyone is happy, the code is tested and reviewed. Wouter Swierstra, Atze Dijkstra Software Project (Lecture 4): Git & Github Feb 2016 42 / 45

Using GitHub Feel free to use GitHub, provided: your client is happy for you to do so; a copy of the repository is hosted on the UU servers (for instance, as an additional remote). There are plenty of alternatives: BitBucket GitLab UU GitLab: git.science.uu.nl (and git.science.uu.nl/help), login with solis id Wouter Swierstra, Atze Dijkstra Software Project (Lecture 4): Git & Github Feb 2016 43 / 45

Best practices Use git tag to tag the version of the repository at the end of every sprint or upon delivering a milestone. Write meaningful commit messages use #x to refer to issue numbers in the GitHub issue tracker. Check your changes regularly using git diff and git status Use git log to review recent commits Caveat: don t commit to the wrong branch! Use separate directories if necessary. Wouter Swierstra, Atze Dijkstra Software Project (Lecture 4): Git & Github Feb 2016 44 / 45

Further reading Scott Chacon s Pro-git Atlassian git tutorials Pull request video tutorial Most common git screwups Wouter Swierstra, Atze Dijkstra Software Project (Lecture 4): Git & Github Feb 2016 45 / 45