Lab Exercise Git: A distributed version control system

Similar documents
Lab Exercise Test First using JUnit

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

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

TDDC88 Lab 4 Software Configuration Management

Lab Exercise Refactoring using Eclipse

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

Object Oriented Programming. Week 1 Part 2 Git and egit

Version control system (VCS)

Version Control with Git

GETTING STARTED WITH. Michael Lessard Senior Solutions Architect June 2017

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

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

Version Control with GIT

Version Control. Version Control

Tutorial 2 GitHub Tutorial

Source Code Management wih git

Introduction to distributed version control with git

Git, the magical version control

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

GIT FOR SYSTEM ADMINS JUSTIN ELLIOTT PENN STATE UNIVERSITY

Fundamentals of Git 1

Computer Science Design I Version Control with Git

Git Introduction CS 400. February 11, 2018

Submitting your Work using 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.

Version control with git and Rstudio. Remko Duursma

Git: Distributed Version Control

GIT VERSION CONTROL TUTORIAL. William Wu 2014 October 7

Git & Github Fundamental by Rajesh Kumar.

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

Git. Presenter: Haotao (Eric) Lai Contact:

CS 390 Software Engineering Lecture 4 - Git

Revision control. INF5750/ Lecture 2 (Part I)

Version Control. Version Control

Windows. Everywhere else

Software Development I

Revision Control and GIT

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

Git: Distributed Version Control

Software Project (Lecture 4): Git & Github

Using Git to Manage Source RTL

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


213/513/613 Linux/Git Bootcamp. Cyrus, Eugene, Minji, Niko

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

Introduction to Version Control

Version Control System - Git. zswu

A BASIC UNDERSTANDING OF VERSION CONTROL

Improving Your Life With Git

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

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:

A Brief Git Primer for CS 350

FEEG Applied Programming 3 - Version Control and Git II

Assumptions. GIT Commands. OS Commands

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

Code Repository. P Blanchfield

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

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

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

John DeDourek Professor Emeritus Faculty of Computer Science University of New Brunswick GIT

Version control with Git.

b. Developing multiple versions of a software project in parallel

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

Lecture 2: Data in Linguistics, Git/GitHub, Jupyter Notebook. LING 1340/2340: Data Science for Linguists Na-Rae Han

Visualizing Git Workflows. A visual guide to 539 workflows

A quick (and maybe practical) guide to Git and version control. By Jay Johnson

INET

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

Software Development. Using GIT. Pr. Olivier Gruber. Laboratoire d'informatique de Grenoble Université de Grenoble-Alpes

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

#25. Use Source Control in a Single- Developer Environment

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

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

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

Human-Computer Interaction Design

! #Running this command from the top directory of your project will add all your changes."! $ git add."

L Modeling and Simulating Social Systems with MATLAB

Git for Version Control

Git version control with Eclipse (EGit) Tutorial

CS 320 Introduction to Software Engineering Spring February 06, 2017

Effective Software Development and Version Control

Version Control with Git

CSE 391 Lecture 9. Version control with Git

Version Control Systems (VCS)

Using GitHub to Share with SparkFun a

Github/Git Primer. Tyler Hague

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

School of Computing Science Gitlab Platform - User Notes

Version Control Systems

Lab 1 1 Due Wed., 2 Sept. 2015

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

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

GIT. A free and open source distributed version control system. User Guide. January, Department of Computer Science and Engineering

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

A brief introduction to the GitLab service at the department

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

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

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

Chapter 5. Version Control: Git

Human-Computer Interaction Design

Transcription:

Lunds tekniska högskola Datavetenskap, Nov 21, 2016 EDAF45 Programvaruutveckling i grupp projekt Labb 2 (Git): Labbhandledning Checked on Git versions: 2.7.4 Lab Exercise Git: A distributed version control system Goal This lab is intended to demonstrate basic usage of git, a distributed version control system. You are supposed to work in pairs on one computer, simulating a small software team developing a simple program component under version control. The lab also demonstrates the XP practices of Collective Ownership and Continuous Integration. The lab is divided into two parts. In part one you will learn git working from the command line. In part two you will instead do all version control directly from within Eclipse. Note! During the lab, keep notes of what you do. You may use a text file instead of paper for your notes, if you think that is easier. Write down the commands that you use and brief descriptions of the results. Write down brief answers to all questions appearing in this lab text. Be prepared to discuss your notes with the lab coach. As part of the explanation we sometimes refer to CVS and compare git commands with CVS commands. This is because you might already be familiar with CVS and the comparison will make it easier for you to understand. If you are not familiar with CVS, just ignore this comparisons and focus on the git commands. 1 Working from the command line Later in this lab and also in the project, you will use version control tools in Eclipse. However, in the first part of this lab exercise you will work with the version control tools directly from the command line, and edit files using an ordinary text editor. This will give you a better insight into how the tools work, than if you had only used them via Eclipse. If you are unfamiliar with unix concepts and commands, you can find information in Introduktion till LTH:s Unixdatorer (http://www.ddg.lth.se/perf/unix/ unix-x.pdf), and you can also google different commands. 2 Introduction In this lab you will meet and, i.e. you will play the roles of and to try out Git. and are planning to move their development to the new popular version control system Git. They want to start working in a simple way, similar to CVS, with a common central repository that they both can commit changes to, or rather, using Git parlance, they will push changes to it. Since Git works a bit differently from CVS, they draw two figures to get a better understanding of similarities and differences. In figure 1 it is shown how checkout is used in CVS to create a local workspace from the 1

common repository. In Git, the command clone is used instead, which creates both a local repository and an associated workspace. The local repository is a clone of the common repository, and contains all the versions of the software. The common repository is bare, meaning that it does not have any associated workspace. CVS common repo! Git common "bare" repo! checkout! checkout! clone! clone!!!!! Figure 1: Creating a local workspace. In Git, a local repository is created along with the workspace. Figure 2 shows how a developer works. In CVS, the developer updates the workspace to get the latest version from the repository, edits files, and then commits the changes to the common repository. In Git, the developer pulls the latest version from the common repository to his/her own local repository/workspace, then edits files, then commits the changes to the local repository, and finally pushes changes in the local repository back to the common repository. CVS common repo! Git common "bare" repo! update! commit! update! commit! pull! push! pull! push! edit! edit! edit! edit!!! commit!! commit!! Figure 2: Working with CVS and Git. In Git, the changes are first committed to the local repository. Then the changes are pushed to the common repository. 2

Now, study the two figures and make sure you understand what clone, pull, commit, push, and bare means in Git. Write down your own descriptions here: clone pull commit push bare and now have some doubts about Git because it would seem that it could take a lot of space to have the complete repository locally. And in CVS you can check out a single module from the repository, whereas in Git you get a workspace for the latest version of the complete repository. However, after consulting with others, they find out the following: Git uses compression algorithms to keep down the size of the repositories. But to keep down the size it is also important to commit only source data, like source files and text files, and avoid committing large generated binary files, like class files and jar files. In CVS it is common to have a large repository with many submodules, e.g., for different products or packages. But in Git, you typically have many smaller repositories instead. and still think that Git looks a bit more complicated than CVS, so they wonder about what the advantages could be. Again, they consult with others and get a lot of different answers, for example the following: You can work locally, committing to your own local repo, without any network connection. You can create branches locally, without needing to make them visible to others. You can create your own repositories locally, so you can get the benefits of version control for your own private work, not just for collaboration. Instead of using a central repository, you can push and pull directly between developer repositories, creating your own work policies. If the central server breaks down, you will still have all your data, and can keep on working. It s the most popular version control system right now, so you get a lot of cool support from source code hosting providers like GitHub, BitBucket, Google Code, and others. Encouraged by this, and think it is worth giving Git a try. They will build a simple HelloWorld application and version control it using Git. In the following, you should play the roles of and, as indicated by the box in the margin. 3 starts working locally is eager to get started. She rushes ahead and creates a new directory for the project in her pvglab2 directory, and creates an empty EADME file for the project. $ mkdir pvglab2 $ cd pvglab2 $ mkdir HelloProject $ cd HelloProject $ touch EADME 3

thinks about this wonderful news that she can have her own local git repository, and get version control on her own code. She decides to try this out before contacting about any collaboration. 3.1 Configuring git has never worked with git before, so she first configures git with her name, email, and the default text editor she would like to use (nano is still her favorite text editor): $ git config --global user.name " Wonderland" $ git config --global user.email alicedat12@student.lth.se $ git config --global core.editor nano She then checks her current configuration, to make sure the new info is there: $ git config --list She wonders where this information is stored, and finds out that it is in a file called.gitconfig, in her home directory, so she looks at its content: $ less ~/.gitconfig 3.2 Creating a local repository creates a local repository simply by doing the git command init in her new project directory, adding all files (currently just the EADME file), and committing them to the new repository: $ cd HelloProject $ git init $ git add. $ git commit -m "New project" She wonders where git placed the repository, and finds it in a subdirectory.git. She takes a look at the contents of the repo, just out of curiosity: $ ls -l.git She notes that there are files and directories called HEAD, branches, config, etc., and she thinks this looks just like the kind of stuff you would expect in a version control repository. 3.3 Working with the local repository now starts working with her local repository. She edits the EADME file, and commits again, checking the git status in between the commands, and checking the commit log: $ git status $ nano EADME $ git status $ git add EADME $ git status $ git commit -m "Updated EADME" $ git status $ git log 4

She notes some things: She is working on a branch called master Before committing she needs to add new and changed files to the so called staging area Changed files can be staged by using the -a option for commit, instead of explictly doing an add When there is nothing to commit, the working directory is said to be clean also finds out that each commit is identified by a long hexadecimal string, like 6b8736fe84cb3e842352af055e0b3948e602fc80 She finds out that this is a hash value of the contents of the committed version and its complete history of earlier versions. also finds out that these hash values (produced by the SHA-1 secure hash algorithm) are sufficiently unique, so that it is extremely unlikely that two different commits would get the same hash code. In fact, she read somewhere that a hash collision might occur if you had 2**80 commits, which incidentally is the same order of magnitude as the number of atoms in the universe. So feels pretty confident it will not happen in her project. She also finds out that Git uses these hash values internally to identify files, directories, etc., to be able to decide extremely quickly if two files/trees/commits, etc. are equal or not, i.e., without having to actually compare the contents. notes that commands like commit and push use seven-digit hexadecimal numbers, like 6b8736f, and she finds out that this is simply a way of abbreviating the long hash values by only showing the first seven digits. 4 Setting up a common repository would now like to create a common repository, so that she can invite to start collaborating with her on the new project. She will simply place the common repository in Bitbucket cloud. She will create the repository on her user account there, and give write access. This way, can push to the repository, even if it is located on s account. When logged in to your Bitbucket account at http://bitbucket.org, you will find online help and tutorials that you can look at if needed. 4.1 Creating the common repository now log in to Bitbucket and creates a new repository. She calls the new repository HelloProject. She makes it private. She also, already now, gives write access to her repo (in Settings and User and group access ) so that he will be able to push into it. 4.2 Connecting the developer repository to the common repository now needs to connect her developer repository to the new common repository and push its contents to it. She goes to the developer repository and performs the following magic for doing this: $ cd pvglab2/helloproject $ git remote add origin https://<username>@bitbucket.org/<username>/helloproject.git $ git push -u origin master where <username> is s Bitbucket username. These commands will make it look like the developer repository was cloned from the common repository (although we in fact created the repositories in the opposite order). 5

Out of curiosity, looks up the more precise meaning of these commands and finds out the following: The remote command sets up the common repository as the origin of the developer repository. The push command pushes the master branch of the developer repository into the origin repository. The -u option configures her master branch to track the master branch in the common repository. This has the effect that when she in the future does a git push, the changes will end up in the right place in the common repository. does not entirely grasp all this, but is happy with accepting that the magic probably does what it should. To check that everything works, does a small change to the EADME file, commits it, and pushes it to the common repository. $ nano EADME $ git commit -a -m "Updated EADME" $ git push She also tries the pull command. $ git pull Of course, nothing new is pulled, since has not started working yet. Avoiding writing the password? thinks it is a bit tedious to have to write the bitbucket password for every pull or push. She knows this can be avoided by ssh and generating an ssh key, but she thinks this is too much work for this short experiment with git. 5 invites to work on the project now invites to work on the project. He starts by configuring git in a similar way as did. 5.1 Cloning the common repository clones the common repository into a suitable place in his own account, and checks the contents of his working directory. $ cd pvglab2 $ git clone https://< username>@bitbucket.org/< username>/helloproject.git $ cd HelloProject $ ls -a 6

5.2 starts working starts working. He edits the EADME file some more, commits it, and pushes back the changes to the common repository. Write down the commands he uses here: 5.3 pulls the new changes pulls down s changes, and takes a look at the commit log. $ git pull $ git log 5.4 Concurrent development: using stash and now start experimenting with developing at the same time. Just like you should do update before you do commit in CVS, you should do pull before you do commit and push in Git. And just like in CVS, you should make sure that the code is clean (compiles and tests) before committing and pushing. First, try the following scenario where and edit the same file: edits the EADME file and saves it. edits the EADME file and saves it. pulls, commits, and pushes. pulls in order to merge with the latest version before he commits and pushes. What happens? It turns out that you cannot pull if your working directory contains uncommitted files that need to be merged with the pulled changes. now has two options: commit he can commit his changes and then pull stash he can stash away his changes, then do pull, and later apply the stashed changes, merging them with the new version of the files. The stash command takes all the uncommitted changes to the working directory and moves them away to a safe place, the stash, so that all edits are undone, and the working directory is set back to the previous clean state (with no uncommitted changes). The stash apply command takes the changes from the stash, and applies them on the working directory again, i.e., merges them with the files in the working directory. tries the stash option, checking the contents of the EADME file after each step. If necessary, he edits the EADME file before the commit, to make sure it has the desired merged content. 7

$ git stash $ more EADME $ git pull $ more EADME $ git stash apply $ more EADME $ nano EADME $ git commit -a -m "..." $ git push realizes that stash is like a light-weight anonymous branch. 5.5 Continued concurrent development and continue with their development, creating the HelloWorld application. They experiment with different ways of getting into merge situations, making sure that also tries out the stash command. and then reflect on what they have learnt, by writing down descriptions of git concepts and commands: repository working directory staged area stash commit identifier git config git init git clone git status git log git add git commit git push git pull git stash git stash apply 8

6 Part II - Using Git from Eclipse Now you know the basics of git and how to work with Bitbucket cloud as the common repository. In this part of the lab, you will create a Java project in Eclipse and put it under version control using git and Bitbucket. All git commands will be executed from within Eclipse. However, feel free to in parallel see what happens in you local git repository from the command line. 6.1 What to do Study the YouTube clip made by Patrik (https://www.youtube.com/watch?v=jniwjhi8occ). Do exactly the same thing using your bitbucket account, e.g. use account and give write access. Also, start two instances of Eclipse, one from each of your unix accounts, to make it as real as possible simulating two developers working in parallel on the same project. Make sure you experience several possible scenarios of parallel modifications and how they can be solved using git and Eclipse. 7 Learning more and now discuss some additional things they would like to learn about Git, for example how to use branches in Git. As a starting point, they take a look at the official Git site: http://git-scm.com, then they decide it is time for a break. 9