CODE VERSION CONTROL
GIUSEPPE MASETTI
ESCI 872 – APPLIED TOOLS FOR OCEAN MAPPING – FUNDAMENTALS OF RESEARCH SOFTWARE DEVELOPMENT
Durham, NH – November 19 & 21, 2019
V1
WHAT IS CODE VERSION CONTROL?
A mechanism to manage changes to code over time.
• Tracking of per-file creation/modifications/deletion
• Ability to switch to past versions to fix bugs
• Facilitating concurrent work on the same project
Help to protect code from both catastrophes
and casual introduction of human error!
VERSION CONTROL SYSTEM (VCS)
Also known as:
Source Code Management (SCM)
Revision Control System (RCS)
CVS, Subversion, Mercurial, Bazaar, Git, etc.
Essential part of the every-day workflow
of a modern research software development team!
Copyright 2014 - 2019 Black Duck Software, Inc., CC-BY, https://www.openhub.net/repositories/compare
GIT .
• Command-line tool that tracks changes in
files and eases collaboration
• Created in 2005 by Linus Torvalds
• Free and open-source → GNU GPL v2
• Goals:
• Handling large project with speed/efficiency
• Data integrity
• Support for non-linear, distributed development
GFDL. Permission of Martin Streicher, Editor-in-
Chief, LINUXMAG.com. CC BY-SA 3.0
SVN VS. GIT
Git
Repo
Git
Repo
Git
Repo
SVN Central
Repo
Working
Copy
Working
Copy
Working
Copy
Centralized VCS Distributed VCS
IN LINUS’ OWN WORDS
2019 RhodeCode, https://rhodecode.com/insights/version-control-systems-2016
GIT → HOW TO INSTALL
Website → https://git-scm.com/
OPEN A WINDOWS SHELL,
THEN RETRIEVE THE GIT’S VERSION.
GIT → HOW TO SETUP
GIT SETUP
• Configure Git with your name and email
• git config --global user.email "your@email.com"
• git config --global user.name "your name"
• Check the current configuration
• git config --list
• The config commands only need to be done once
IN A WINDOWS SHELL
CONFIGURE GIT
WITH YOUR NAME AND EMAIL.
GIT → HOW TO USE
USING GIT
• Creating a new project
• git init → convert a directory into a Git repository (a .git directory is created)
• git add . → a snapshot of the directory content in a temporary staging area
• git commit –m "First commit" → permanently store the snapshot
• The init commands only need to be done once per project.
IN A WINDOWS SHELL
CREATE A GIT PROJECT, THEN
CREATE AND COMMIT A README FILE.
USING GIT
• Making code changes
• git add file0.py file1.py → stage new/updated files
• git diff → to list un-staged changes
• git diff --cached → to see what is ready to be committed
• git status → a brief summary of the repository situation
• git commit –m "A meaningful message" → finally commit your changes
USING GIT
• Making code changes
• git diff → to list un-staged changes
• git add file0.py file1.py → stage new/updated files
• git diff --cached → to see what is ready to be committed
• git status → a brief summary of the repository situation
• git commit –m "A meaningful message" → finally commit your changes
• When to commit code?
• Do it frequently
• Whenever you have reached a milestone/step in your task
FIRST CREATE AND COMMIT TWO SCRIPT FILES,
THEN EDIT ONE OF THEM AND
COMMIT THE CHANGES.
LOCAL CLOUD
Working
Directory
Staging
Area
Local
Repository
Remote
Repository
git add
git commit
git push
git fetch
git checkout
git merge
GIT HOSTING SERVICES
• Several sites offer services for hosting Git repositories
• Popular ones that are free for open-source projects:
GITHUB
• A social network for code share/collaboration
• It was acquired by Microsoft in 2018 for $7.5 billion.
GITHUB
• A social network for code share/collaboration
• It was acquired by Microsoft in 2018 for $7.5 billion.
• To push to the GitHub repository:
• Setup a remote (just once):
• git remote add origin https://github.com/giumas/myproject.git
• Push committed code (multiple times):
• git push origin master
• Reload project webpage
PUSH THE PREVIOUSLY CREATED PROJECT CODE
TO A GIT HOSTING SERVICE.
EPOM SERVER → JUPYTER TERMINAL
EPOM SERVER → CLONING GIT REPO
git clone https://github.com/giumas/myproject.git
EPOM SERVER → GIT REPO HISTORY
git log
EPOM SERVER → RUN A SCRIPT
ON THE EPOM SERVER
CLONE YOUR GIT REPOSITORY,
THEN EXECUTE ONE OF THE SCRIPTS.
LOCAL MACHINE GITHUB
Git
Repository
Git
Repository
git push
EPOM SERVER
git clone
Git
Repository
git push
git pull
git push
git pull
git push
COMMIT CHANGES ON YOUR LOCAL MACHINE,
THEN RETRIEVE THEM ON THE EPOM SERVER.
https://jrebel.com/rebellabs/git-commands-and-best-practices-cheat-sheet/
GIT GUI CLIENT → TORTOISEGIT
A windows shell extension to work with Git repositories.
• Shell integration
• Icon overlays
• Easy access to Git commands
TORTOISEGIT → ICON OVERLAYS
• Normal → all changes committed
• Modified → changes are present
• Staged → changes are ready to be committed
• Deleted → file/folder scheduled to be deleted
• Added → file/folder scheduled to be added
• Ignored → file/folder ignored by Git
• Conflict → there is a conflict between code versions
https://tortoisegit.org/docs/tortoisegit/tgit-dug-wcstatus.html#tgit-dug-wcstatus-1
TORTOISEGIT → SWITCH TO PAST COMMITS
TORTOISEGIT → SWITCH TO PAST COMMITS
TORTOISEGIT → SWITCH TO PAST COMMITS
TORTOISEGIT → SWITCH TO PAST COMMITS
USING TORTOISEGIT
SWITCH TO A PAST COMMIT,
THEN EXECUTE THE RESULTING SCRIPT.
QUESTIONS?
Contact me at: gmasetti@ccom.unh.edu

ePOM - Fundamentals of Research Software Development - Code Version Control

  • 1.
    CODE VERSION CONTROL GIUSEPPEMASETTI ESCI 872 – APPLIED TOOLS FOR OCEAN MAPPING – FUNDAMENTALS OF RESEARCH SOFTWARE DEVELOPMENT Durham, NH – November 19 & 21, 2019 V1
  • 2.
    WHAT IS CODEVERSION CONTROL? A mechanism to manage changes to code over time. • Tracking of per-file creation/modifications/deletion • Ability to switch to past versions to fix bugs • Facilitating concurrent work on the same project Help to protect code from both catastrophes and casual introduction of human error!
  • 3.
    VERSION CONTROL SYSTEM(VCS) Also known as: Source Code Management (SCM) Revision Control System (RCS) CVS, Subversion, Mercurial, Bazaar, Git, etc. Essential part of the every-day workflow of a modern research software development team!
  • 4.
    Copyright 2014 -2019 Black Duck Software, Inc., CC-BY, https://www.openhub.net/repositories/compare
  • 5.
    GIT . • Command-linetool that tracks changes in files and eases collaboration • Created in 2005 by Linus Torvalds • Free and open-source → GNU GPL v2 • Goals: • Handling large project with speed/efficiency • Data integrity • Support for non-linear, distributed development GFDL. Permission of Martin Streicher, Editor-in- Chief, LINUXMAG.com. CC BY-SA 3.0
  • 6.
    SVN VS. GIT Git Repo Git Repo Git Repo SVNCentral Repo Working Copy Working Copy Working Copy Centralized VCS Distributed VCS
  • 7.
  • 8.
  • 9.
    GIT → HOWTO INSTALL
  • 10.
  • 13.
    OPEN A WINDOWSSHELL, THEN RETRIEVE THE GIT’S VERSION.
  • 14.
    GIT → HOWTO SETUP
  • 15.
    GIT SETUP • ConfigureGit with your name and email • git config --global user.email "your@email.com" • git config --global user.name "your name" • Check the current configuration • git config --list • The config commands only need to be done once
  • 16.
    IN A WINDOWSSHELL CONFIGURE GIT WITH YOUR NAME AND EMAIL.
  • 17.
  • 18.
    USING GIT • Creatinga new project • git init → convert a directory into a Git repository (a .git directory is created) • git add . → a snapshot of the directory content in a temporary staging area • git commit –m "First commit" → permanently store the snapshot • The init commands only need to be done once per project.
  • 20.
    IN A WINDOWSSHELL CREATE A GIT PROJECT, THEN CREATE AND COMMIT A README FILE.
  • 21.
    USING GIT • Makingcode changes • git add file0.py file1.py → stage new/updated files • git diff → to list un-staged changes • git diff --cached → to see what is ready to be committed • git status → a brief summary of the repository situation • git commit –m "A meaningful message" → finally commit your changes
  • 27.
    USING GIT • Makingcode changes • git diff → to list un-staged changes • git add file0.py file1.py → stage new/updated files • git diff --cached → to see what is ready to be committed • git status → a brief summary of the repository situation • git commit –m "A meaningful message" → finally commit your changes • When to commit code? • Do it frequently • Whenever you have reached a milestone/step in your task
  • 28.
    FIRST CREATE ANDCOMMIT TWO SCRIPT FILES, THEN EDIT ONE OF THEM AND COMMIT THE CHANGES.
  • 29.
  • 30.
    GIT HOSTING SERVICES •Several sites offer services for hosting Git repositories • Popular ones that are free for open-source projects:
  • 31.
    GITHUB • A socialnetwork for code share/collaboration • It was acquired by Microsoft in 2018 for $7.5 billion.
  • 36.
    GITHUB • A socialnetwork for code share/collaboration • It was acquired by Microsoft in 2018 for $7.5 billion. • To push to the GitHub repository: • Setup a remote (just once): • git remote add origin https://github.com/giumas/myproject.git • Push committed code (multiple times): • git push origin master • Reload project webpage
  • 39.
    PUSH THE PREVIOUSLYCREATED PROJECT CODE TO A GIT HOSTING SERVICE.
  • 40.
    EPOM SERVER →JUPYTER TERMINAL
  • 41.
    EPOM SERVER →CLONING GIT REPO git clone https://github.com/giumas/myproject.git
  • 42.
    EPOM SERVER →GIT REPO HISTORY git log
  • 43.
    EPOM SERVER →RUN A SCRIPT
  • 44.
    ON THE EPOMSERVER CLONE YOUR GIT REPOSITORY, THEN EXECUTE ONE OF THE SCRIPTS.
  • 45.
    LOCAL MACHINE GITHUB Git Repository Git Repository gitpush EPOM SERVER git clone Git Repository git push git pull git push git pull git push
  • 49.
    COMMIT CHANGES ONYOUR LOCAL MACHINE, THEN RETRIEVE THEM ON THE EPOM SERVER.
  • 50.
  • 51.
    GIT GUI CLIENT→ TORTOISEGIT A windows shell extension to work with Git repositories.
  • 53.
    • Shell integration •Icon overlays • Easy access to Git commands
  • 54.
    TORTOISEGIT → ICONOVERLAYS • Normal → all changes committed • Modified → changes are present • Staged → changes are ready to be committed • Deleted → file/folder scheduled to be deleted • Added → file/folder scheduled to be added • Ignored → file/folder ignored by Git • Conflict → there is a conflict between code versions https://tortoisegit.org/docs/tortoisegit/tgit-dug-wcstatus.html#tgit-dug-wcstatus-1
  • 55.
    TORTOISEGIT → SWITCHTO PAST COMMITS
  • 56.
    TORTOISEGIT → SWITCHTO PAST COMMITS
  • 57.
    TORTOISEGIT → SWITCHTO PAST COMMITS
  • 58.
    TORTOISEGIT → SWITCHTO PAST COMMITS
  • 59.
    USING TORTOISEGIT SWITCH TOA PAST COMMIT, THEN EXECUTE THE RESULTING SCRIPT.
  • 60.
    QUESTIONS? Contact me at:gmasetti@ccom.unh.edu