E-learning Python for Ocean Mapping (ePOM) project.
Complementary slides to the "Code Version Control" module (part of the Fundamentals of Research Software Development training).
More details at https://www.hydroffice.org/epom
The Mariana Trench remarkable geological features on Earth.pptx
ePOM - Fundamentals of Research Software Development - Code Version Control
1. CODE VERSION CONTROL
GIUSEPPE MASETTI
ESCI 872 – APPLIED TOOLS FOR OCEAN MAPPING – FUNDAMENTALS OF RESEARCH SOFTWARE DEVELOPMENT
Durham, NH – November 19 & 21, 2019
V1
2. 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!
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!
5. 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
15. 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
16. IN A WINDOWS SHELL
CONFIGURE GIT
WITH YOUR NAME AND EMAIL.
18. 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.
19.
20. IN A WINDOWS SHELL
CREATE A GIT PROJECT, THEN
CREATE AND COMMIT A README FILE.
21. 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
22.
23.
24.
25.
26.
27. 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
28. FIRST CREATE AND COMMIT TWO SCRIPT FILES,
THEN EDIT ONE OF THEM AND
COMMIT THE CHANGES.
30. GIT HOSTING SERVICES
• Several sites offer services for hosting Git repositories
• Popular ones that are free for open-source projects:
31. GITHUB
• A social network for code share/collaboration
• It was acquired by Microsoft in 2018 for $7.5 billion.
32.
33.
34.
35.
36. 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
54. 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