KEMBAR78
Version Control System - Git | PDF
MILANO 1863
POLITECNICO
Version Control System
REASONS AND GIT
Carlo Bernaschina – carlo.bernaschina@polimi.it
Our day to day work can be described as follow:
• Create
• Save
• Edit
• Save again
• …
Background
DEVELOPMENT CYCLE
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
• …
Collisions
We both changed the same file, which one should we
use?
Journaling
Who changed What? When? Why?
The Problem
COLLISIONS & JOURNALING
A Version Control System is not “just” a backup.
It is a tool that enables:
• Parallel Development
• Journaling
• Collaboration
The Solution
VERSION CONTROL SYSTEM
• CVS
• Centralized (Client/Server)
• Subversion “CVS Made Right”
• Atomic operations
• Git
• Decentralized
• Mercurial
• Linear History
Alternatives
FREE VERSION CONTROL SYSTEMS
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
• 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
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?
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?
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?
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?
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?
Git stores your history of commits.
You move inside the history and start new parallel
development flows called branches.
History
WHAT HAPPENED?
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?
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?
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?
If you want to list all the available branches.
git branch
git branch
HOW DO I LIST MY BRANCHES?
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?
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?
If you want to remove branches, just delete them.
git branch -d <branch name>
git branch -d
HOW DO I CLEAN UP?
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?
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?
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?
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?
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?
Do you want to learn more?
https://try.github.io
Let’s learn
ONLINE LEARNING TOOLS
• https://git-scm.com
• http://www.catb.org/esr/writings/version-
control/version-control.html
• https://www.youtube.com/watch?v=4XpnKHJAok8
• http://marc.info/?l=git&m=118143549107708
Reference

Version Control System - Git

  • 1.
    MILANO 1863 POLITECNICO Version ControlSystem REASONS AND GIT Carlo Bernaschina – carlo.bernaschina@polimi.it
  • 2.
    Our day today work can be described as follow: • Create • Save • Edit • Save again • … Background DEVELOPMENT CYCLE
  • 3.
    Generally we donot work alone. This process is shared between peoples (developers). Background COLLABORATION Donald: • Create • Save • Edit • Save again • … Emily: • Create • Save • Edit • Save again • …
  • 4.
    Collisions We both changedthe same file, which one should we use? Journaling Who changed What? When? Why? The Problem COLLISIONS & JOURNALING
  • 5.
    A Version ControlSystem is not “just” a backup. It is a tool that enables: • Parallel Development • Journaling • Collaboration The Solution VERSION CONTROL SYSTEM
  • 6.
    • CVS • Centralized(Client/Server) • Subversion “CVS Made Right” • Atomic operations • Git • Decentralized • Mercurial • Linear History Alternatives FREE VERSION CONTROL SYSTEMS
  • 7.
    Git is aVersion 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
  • 8.
    • Take ConcurrentVersions 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
  • 9.
    To create arepository 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?
  • 10.
    Let’s Git knowwho 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?
  • 11.
    Once we haveproduced 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?
  • 12.
    If you wantto 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?
  • 13.
    Once we havestaged 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?
  • 14.
    Git stores yourhistory of commits. You move inside the history and start new parallel development flows called branches. History WHAT HAPPENED?
  • 15.
    You can alwaysrestore 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?
  • 16.
    If you wantto 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?
  • 17.
    If you wantto 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?
  • 18.
    If you wantto list all the available branches. git branch git branch HOW DO I LIST MY BRANCHES?
  • 19.
    If you wantto 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?
  • 20.
    If both thebranches 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?
  • 21.
    If you wantto remove branches, just delete them. git branch -d <branch name> git branch -d HOW DO I CLEAN UP?
  • 22.
    We just workedwith 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?
  • 23.
    If you wantto 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?
  • 24.
    If you wantkeep 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?
  • 25.
    If you need/wantto 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?
  • 26.
    If you wantto 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?
  • 27.
    Do you wantto learn more? https://try.github.io Let’s learn ONLINE LEARNING TOOLS
  • 28.
    • https://git-scm.com • http://www.catb.org/esr/writings/version- control/version-control.html •https://www.youtube.com/watch?v=4XpnKHJAok8 • http://marc.info/?l=git&m=118143549107708 Reference