Wolfman and Dracula have been hired by Universal Missions (a space
services spinoff from Euphoric State University) to investigate if it is
possible to send their next planetary lander to Mars. They want to be
able to work on the plans at the same time, but they have run into
problems doing this in the past. If they take turns, each one will spend
a lot of time waiting for the other to finish, but if they work on their
own copies and email changes back and forth things will be lost,
overwritten, or duplicated.
A colleague suggests using version control to manage
their work. Version control is better than mailing files back and
forth:
Nothing that is committed to version control is ever lost, unless
you work really, really hard at it. Since all old versions of files are
saved, it’s always possible to go back in time to see exactly who wrote
what on a particular day, or what version of a program was used to
generate a particular set of results.
As we have this record of who made what changes when, we know who
to ask if we have questions later on, and, if needed, revert to a
previous version, much like the “undo” feature in an editor.
When several people collaborate in the same project, it’s
possible to accidentally overlook or overwrite someone’s changes. The
version control system automatically notifies users whenever there’s a
conflict between one person’s work and another’s.
Teams are not the only ones to benefit from version control: lone
researchers can benefit immensely. Keeping a record of what was changed,
when, and why is extremely useful for all researchers if they ever need
to come back to the project later on (e.g., a year later, when memory
has faded).
Version control is the lab notebook of the digital world: it’s what
professionals use to keep track of what they’ve done and to collaborate
with other people. Every large software development project relies on
it, and most programmers use it for their small jobs as well. And it
isn’t just for software: books, papers, small data sets, and anything
that changes over time or needs to be shared can and should be stored in
a version control system.
Prerequisites
In this lesson we use Git from the Unix Shell. Some previous
experience with the shell is expected, but isn’t mandatory.
The Bash Shell
Bash is a commonly-used shell that gives you the power to do tasks
more quickly.
Windows users will install a bash shell called Git Bash when
installing git following the instructions below:
Click on “Next” to accept the license agreement, again to accept the
default installation path, again to select the default components, and a
fourth time to name a start menu folder. (If you have git installed
already, see the note below.)
From the dropdown menu select “Use the nano editor by default” and
click on “Next”.
Select “Override the default branch name for new repositories” and
leave it set to main. Click on “Next”.
Ensure that “Git from the command line and also from 3rd-party
software” is selected and click on “Next”. (If you don’t do this Git
Bash will not work properly, requiring you to remove the Git Bash
installation, re-run the installer and to select the “Git from the
command line and also from 3rd-party software” option.)
Select “Use bundled OpenSSH” and click on “Next”.
Select “Use the native Windows Secure Channel library” and click on
“Next”.
Ensure that “Checkout Windows-style, commit Unix-style line endings”
is selected and click on “Next”.
Ensure that “Use Windows’ default console window” is selected and
click on “Next”.
Ensure that “Default (fast-forward or merge) is selected and
click”Next”
Ensure that “Get Crediential Manager” is selected and click on
“Next”.
Ensure that “Enable file system caching” is checked and click on
“Next”.
Do not enable either of the “experimental options”. Click
“Install”.
Click on “Finish” or “Next”.
If your “HOME” environment variable is not set (or you don’t know
what this is):
Open command prompt (Open Start Menu then type cmd and
press Enter)
Type the following line into the command prompt window exactly as
shown: setx HOME "%USERPROFILE%"
Press Enter, you should see SUCCESS: Specified value was saved.
Quit command prompt by typing exit then pressing Enter This will
provide you with both Git and Bash in the Git Bash program.
If you already have git installed, running the installer will upgrade
to the newest verison, currently 2.35.1.2. When you launch the
installer, ensure “Only show new options” is
unchecked.
The default shell in some versions of macOS is Bash, and Bash is
available in all versions, so no need to install anything. You access
Bash from the Terminal (found in /Applications/Utilities).
You may want to keep Terminal in your dock for this workshop.
To see if your default shell is Bash type echo $SHELL in
Terminal and press the Return key. If the message printed does not end
with ‘/bash’ then your default is something else and you can run Bash by
typing bash
If you want to change your default shell, see this Apple Support
article and follow the instructions on “How to change your default
shell”.
The default shell is usually Bash and there is usually no need to
install anything.
To see if your default shell is Bash type echo $SHELL in
a terminal and press the Enter key. If the message printed does not end
with ‘/bash’ then your default is something else and you can run Bash by
typing bash.
Git
Git is a version control system that lets you track who made changes
to what when and has options for easily updating a shared or public
version of your code on github.com.
You will need a supported
web browser.
You will need an account at github.com for parts of the Git lesson.
Basic GitHub accounts are free. We encourage you to create a GitHub
account if you don’t have one already. Please consider what personal
information you’d like to reveal. For example, you may want to review
these instructions for keeping
your email address private provided by GitHub.
Git should be installed on your computer as part of your Bash install
(see the Shell installation instructions above).
Please open the Terminal app, type git --version and
press Enter/Return. If it’s not installed already, follow the
instructions to Install the “command line developer tools”.
Do not click “Get Xcode”, because that will take too
long and is not necessary for our Git lesson. After installing these
tools, there won’t be anything in your /Applications folder, as they and
Git are command line programs. For older versions of OS X
(10.5-10.8) use the most recent available installer labelled
“snow-leopard” available
here. (Note: this project is no longer maintained.) Because this
installer is not signed by the developer, you may have to right click
(control click) on the .pkg file, click Open, and click Open in the
pop-up dialog.
If Git is not already available on your machine you can try to
install it via your distro’s package manager. For Debian/Ubuntu run
sudo apt-get install git and for Fedora run
sudo dnf install git.