Top Banner
MILANO 1863 POLITECNICO Version Control System REASONS AND GIT Carlo Bernaschina [email protected]
28

Version Control System - Git

Feb 14, 2017

Download

Software

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Version Control System - Git

MILANO 1863 POLITECNICO

Version Control System

REASONS AND GIT

Carlo Bernaschina – [email protected]

Page 2: Version Control System - Git

Our day to day work can be described as follow:

• Create

• Save

• Edit

• Save again

• …

Background DEVELOPMENT CYCLE

Page 3: Version Control System - Git

Generally we do not work alone.

This process is shared between peoples (developers).

Background COLLABORATION

Donald:

• Create

• Save

• Edit

• Save again

• …

Emily:

• Create

• Save

• Edit

• Save again

• …

Page 4: Version Control System - Git

Collisions

We both changed the same file, which one should we

use?

Journaling

Who changed What? When? Why?

The Problem COLLISIONS & JOURNALING

Page 5: Version Control System - Git

A Version Control System is not “just” a backup.

It is a tool that enables:

• Parallel Development

• Journaling

• Collaboration

The Solution VERSION CONTROL SYSTEM

Page 6: Version Control System - Git

• CVS

• Centralized (Client/Server)

• Subversion “CVS Made Right”

• Atomic operations

• Git

• Decentralized

• Mercurial

• Linear History

Alternatives FREE VERSION CONTROL SYSTEMS

Page 7: Version Control System - Git

Git is a Version Control System.

It was developed by Linus Torvalds in 2005 for the

development of the Linux Kernel.

It was originally meant to replace BitKeeper.

Git A FREE AND OPEN SOURCE ALTERNATIVE

not actually directed to BitKeeper

Page 8: Version Control System - Git

• Take Concurrent Versions System (CVS) as an

example of what not to do; if in doubt, make the

exact opposite decision

• Support a distributed, BitKeeper-like workflow

• Include very strong safeguards against corruption,

either accidental or malicious

Linus Torvalds

The Original Idea SOME GUIDING RULES

Page 9: Version Control System - Git

To create a repository you just need to type:

git init

it creates a repository inside the current folder.

Or:

git init <directory>

it creates a repository inside a specific directory.

git init HOW DO I CREATE A REPOSITORY?

Page 10: Version Control System - Git

Let’s Git know who we are. Using:

git config user.name “<your name>"

git config user.email “<your email>"

These information will be attached to each commit

that we are going to do (journaling).

git config WHO AM I?

Page 11: Version Control System - Git

Once we have produced some content let’s Git know

what do we want to save (stage for commit).

git add <file>

will stage the specified file for commit.

git add -A

will stage All the files for commit.

git add WHAT AM I SAVING?

Page 12: Version Control System - Git

If you want to have a list of the currently changed/staged files you can list them.

git status

Files can be in different states:

• at revision (no change since last commit)

• changed (added, edited or deleted)

• staged (changed and listed for commit)

git status WHAT DID I DO?

Page 13: Version Control System - Git

Once we have staged all the files it is time so actually

commit the changes.

git commit

will open a command line editor and let you specify a

commit message.

git commit -m "<a meaningful commit message>"

the same but easier.

git commit WHY DID I DO THAT?

Page 14: Version Control System - Git

Git stores your history of commits.

You move inside the history and start new parallel

development flows called branches.

History WHAT HAPPENED?

Page 15: Version Control System - Git

You can always restore the last stored version of a file.

git checkout <file name>

All the local edits will be overwritten.

git checkout HOW DO I COME BACK?

Page 16: Version Control System - Git

If you want to preserve the current status of the

repository you can create a new branch (a separate

development flow).

git checkout -b <new branch name>

It will clone the current status of the repository in a new

branch.

git checkout HOW DO I START DEVELOPING A NEW FEATURE?

Page 17: Version Control System - Git

If you want to move between the available branches

you can checkout the one you want to work on.

git checkout <branch name>

It will set the selected branch as active.

git checkout HOW DO I MOVE BETWEEN BRANCHES?

Page 18: Version Control System - Git

If you want to list all the available branches.

git branch

git branch HOW DO I LIST MY BRANCHES?

Page 19: Version Control System - Git

If you want to integrate the changes done in a branch

into another.

Move to the branch you want to merge to and merge

them.

git checkout <target branch>

git merge <source branch>

git merge HOW DO I INTEGRATE TWO BRANCHES?

Page 20: Version Control System - Git

If both the branches have a commit that changes the same content it will generate a conflict.

the number of planets are

<<<<<<< HEAD

nine

=======

Eight

>>>>>>> branch-a

Manually fix them and then commit.

Conflicts HOW DOES IT MERGE CONFLICTING CONTENT?

Page 21: Version Control System - Git

If you want to remove branches, just delete them.

git branch -d <branch name>

git branch -d HOW DO I CLEAN UP?

Page 22: Version Control System - Git

We just worked with local repositories right now.

How can we collaborate.

Git is decentralized, the copies of the repositories on different machines describe a graph.

A way to have a “central” copy of the repository that is accessible to everyone without the need of particular setups is using sites like:

• github.com

• gitlab.com

Distributed HOW DO WE COLLABORATE?

Page 23: Version Control System - Git

If you want to copy a remote repository just clone it.

git clone <address of the repository>

It will copy the remote repository on the local machine.

git clone HOW DO I COPY A REMOTE REPOSITORY?

Page 24: Version Control System - Git

If you want keep your clone updated you can pull the

changes from the remote one.

git pull

It will merge the remote changes inside the local

repository.

git pull <remote> <branch>

git pull HOW DO I UPDATE MY COPY?

Page 25: Version Control System - Git

If you need/want to maintain sequentiality in the

commits adding your local changes after the others

you can ask the merge utility to apply them after the

others.

git pull --rebase

You will be asked to confirm some of your commits.

git pull --rebase <remote> <branch>

git pull --rebase HOW DO I KEEP JOURNALING SEQUENTIAL?

Page 26: Version Control System - Git

If you want to send your local commits to a remote

repository you can push them.

git push

It will copy the local changes on the remote repository.

It requires the last commit in the remote repository to

be known in the local one.

git push <remote> <branch>

git push HOW DO I UPLOAD MY CHANGES?

Page 27: Version Control System - Git

Do you want to learn more?

https://try.github.io

Let’s learn ONLINE LEARNING TOOLS