[2015/2016] collaborative software development with git

41
Ivano Malavolta Collaborative software development with Git

Upload: ivano-malavolta

Post on 12-Apr-2017

690 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: [2015/2016] Collaborative software development with Git

Ivano Malavolta

Collaborative software development

with Git

Page 2: [2015/2016] Collaborative software development with Git
Page 3: [2015/2016] Collaborative software development with Git

Roadmap

Concepts & workflow

Commands

Branching

GitHub

Lab

Page 4: [2015/2016] Collaborative software development with Git

Global software engineering

Global softwareengineering

Collaboration Coordination

Communication Awareness

Page 5: [2015/2016] Collaborative software development with Git

Global software engineering

CollaborationWhen the technology brings improvements to the shared space or to the way users interact with shared artifacts synchronously or asynchronously

CoordinationWhen the technology brings improvements to the support offered for people managing themselves, or themselves within a team

CommunicationWhen the technology brings improvements to the way messages and information are exchanged among people, reducing gaps, ambiguity, or the effort needed to understand, establish, or continue a conversation

AwarenessAn understanding of the activities of others, which provides a context for your own activity

Page 6: [2015/2016] Collaborative software development with Git

Version control

“A system that records changes to a file or set of files over time so that you can recall specific versions later”

Files can refer to anything:

• source files

• images

• Powerpoint slides

• documents

à more concretely, if you screw things up or lose files, you can easily recover!

Page 7: [2015/2016] Collaborative software development with Git

Local version control

Page 8: [2015/2016] Collaborative software development with Git

Centralized version control

CVS

Page 9: [2015/2016] Collaborative software development with Git

Distributed version control

Page 10: [2015/2016] Collaborative software development with Git

Git

• Distributed Source Control system

• Open source, free (GNU GPL V2)

• Came out of Linux development community – Linus Torvalds, 2005

• Goals:– Speed – Simple design – Strong support for non-linear development (thousands of parallel

branches) – Fully distributed – Able to handle large projects like the Linux kernel efficiently

(speed and data size)

Page 11: [2015/2016] Collaborative software development with Git

Key points of Git

• Snapshot-based– no deltas

• Integrity– Checksums as identification scheme

• Three states– working-staging-production

Page 12: [2015/2016] Collaborative software development with Git

Key points: snapshot based

Storing data as changes to a base version of each file

Storing data as snapshots of the project over time

Page 13: [2015/2016] Collaborative software development with Git

key points: integrity

• Everything in Git is check-summed before it is stored– This means it’s impossible to change the contents of any file or directory

without Git knowing about it

• Git generates a unique SHA-1 hash – 40 character string of hex digits, for every commit

• Git identifies files and directories by their ID rather than a version number– Often you will see only the first 7 characters:

1677b2d Edited first line of readme258efa7 Added line to readme0e52da7 Initial commit

Page 14: [2015/2016] Collaborative software development with Git

Key points: 3 states

These are all local changes

Page 15: [2015/2016] Collaborative software development with Git

Key points: 3 states

You modify files in your working directory

Basic Git workflow:

You stage the files, adding snapshots of them to your staging area

You do a commit, which takes the files as they are in the staging area and stores that snapshot permanently to your Git directory

1

2

3

Page 16: [2015/2016] Collaborative software development with Git

A more complete workflow

http://documentup.com/skwp/git-workflows-book

Page 17: [2015/2016] Collaborative software development with Git

Commands

Contents of this part of lecture coming fromhttps://training.github.com/kit/downloads/github-git-cheat-sheet.pdf

Page 18: [2015/2016] Collaborative software development with Git

Commands

Page 19: [2015/2016] Collaborative software development with Git

Commands

Page 20: [2015/2016] Collaborative software development with Git
Page 21: [2015/2016] Collaborative software development with Git

Commands

Page 22: [2015/2016] Collaborative software development with Git

Commands

Page 23: [2015/2016] Collaborative software development with Git

Commands

Page 24: [2015/2016] Collaborative software development with Git

Commands

Page 25: [2015/2016] Collaborative software development with Git

Commands

Page 26: [2015/2016] Collaborative software development with Git

Commands

Page 27: [2015/2016] Collaborative software development with Git

Branching

Page 28: [2015/2016] Collaborative software development with Git

Branching

Branch = an independent line of development

Each branch has its own working directory, staging area, and project history

Git branches are extremely light and fast– Instead of copying files from directory to directory, Git stores a branch as a

reference to a commit

image from https://www.atlassian.com/git/tutorials/using-branches/git-branch

Page 29: [2015/2016] Collaborative software development with Git

Branching workflow

Git ENCOURAGES workflows that branch and merge often, even multiple times in a day

When you want to add a new feature or fix a bug—no matter how big or how small—you spawn a new branch to encapsulate your changes

https://www.atlassian.com/git/tutorials/using-branches/git-branch

The main code base is always stable

It is possible to work in parallel on different features

Page 30: [2015/2016] Collaborative software development with Git

Branching and merging

Imagine you already have 3 commits in your project

Master = The main branch in your project – Doesn’t have to be called master, but almost always is!

Page 31: [2015/2016] Collaborative software development with Git

Creating branches

You have to fix issue #53 of your project

à you create a branch called iss53

You fix the issue and commit

Page 32: [2015/2016] Collaborative software development with Git

Switching branches

Now there is an issue with your production code (e.g., a new bug)

à you have to switch to the master branch

Let’s make the hotfix

By doing this, Git will reset your working directory at the last commit of the branch

Page 33: [2015/2016] Collaborative software development with Git

Merging branches

After you checked your hotfix, you can put it in production

à you merge the hotfix branch with master

Let’s make the hotfix

Fast-forward: Git just moves the master pointer forward towards hotfix

Page 34: [2015/2016] Collaborative software development with Git

Deleting branches

Now the hotfix branch is no longer needed because it points to the same place as masterà you delete the hotfix branch

And now you can continue working on your iss53

Page 35: [2015/2016] Collaborative software development with Git

Merging branches

If your work on iss53 is finished, then you can put it in production

à you merge iss53 into the master branch

This is not a fast-forward merge

In this case Git automatically does a 3-way merge between the 2 snapshots to be merged and the common ancestor

Page 36: [2015/2016] Collaborative software development with Git

Merging branches 1

If your work on iss53 is finished, then you can put it in production

à you merge iss53 into the master branch

This is not a fast-forward merge

In this case Git automatically does a 3-way merge between the 2 snapshots to be merged and the common ancestor

Page 37: [2015/2016] Collaborative software development with Git

Merging branches 2

Git automatically creates:

1. a new snapshot containing the result of the 3-way merge

2. a new commit pointing to the new snapshot

If you changed the same part of the same file -> CONFLICT

Page 38: [2015/2016] Collaborative software development with Git

GitHub

A site for online storage of Git repositories– You can get free space for open source projects – or you can pay for private projects

Adds extra functionalities, like:– web UI– documentation– bug tracking (issues)– feature requests, pull requests– social interactions among developers

• following, check activities, discover new repos

It is not mandatory, you can:

• use Git locally

• setup a private Git server

Page 39: [2015/2016] Collaborative software development with Git

Lab

1. Register to GitHub

2. fork this repo: https://github.com/iivanoo/rest-biter3. create a Python script your_name.py

4. in the script, add a simple function definition that does something(even just a print statement)

5. in restBiter.py add:– an import statement for importing your Python script of step 4– a statement for calling the function defined in your Python script

6. test the main function by running the script in the terminal:python restBiter.py http://www.google.com 2 0 500 1000

7. do commit and push your changes to your repo

8. [optional] open a new pull request to merge your changes with the original repo

Page 40: [2015/2016] Collaborative software development with Git

References

• Official git site and tutorials– https://git-scm.com

• GitHub guides– https://guides.github.com

• Commands cheatsheet– https://training.github.com/kit/downloads/github-git-cheat-sheet.pdf

Page 41: [2015/2016] Collaborative software development with Git

ContactIvano Malavolta |

Post-doc researcherGran Sasso Science Institute

iivanoo

[email protected]

www.ivanomalavolta.com