Versioning

No Version Control

https://phdcomics.com/comics/archive.php?comicid=1531
  • Idiosyncratic version naming looms
  • Requires thinking about version names
  • Which one is the most recent version?
  • Collaboration often leads to conflicts
  • Sometimes manual merges required

Version Control with git

git makes version control easier, comprehensible, and more secure

  • Collaborate on files
    git eases the pain of merging conjointly edited files
    Everyone with access rights can participate
  • Track file changes
    When and by whom was a file changed in which way—and why?
  • Reverse file(s)—or the entire project—to an earlier stage
    Accidently deleted a file/folder?
    Code stopped working?

Preliminaries

Do You Have git installed?

git usually comes installed on Linux and MacOS computers

Wanna make sure?

MacOs

  • Start Spotlight (e.g., by pressing ⌘ + Space)
  • Type terminal and hit the ⏎ key
  • In the Terminal, type
    git version

Linux

  • Hit the Super key (usually the ‘Windows’ key)
  • Type terminal
  • In the Terminal, type
    git version

If you get a version number as response, git is installed on your computer

Install git

If you got an error message as response to git version, you first have to install it.

To install git, go to
https://git-scm.com/downloads

Configure git

To configure git for your computer system, in a Terminal type:

git config --global user.name "your-git-handle"1

followed by

git config --global user.email "your.name@ivy.edu"

If you use git on the same computer with a different username and/or email address for some projects, you need to do this again with the project-related information in each of the other projects’ top folders without!!! the ‘--global’ switch.

Do you Have an SSH Key?

In a Terminal, type:

cd ~

followed by

ls .ssh/

If this does not throw an error but shows at least something like

id_rsa  id_rsa.pub

you do have an SSH key. 🥳

Generate an SSH Key (1)

In case you do not have an SSH key, in a Terminal, type:

ssh-keygen

This yields the response:

Generating public/private rsa key pair.
Enter file in which to save the key (/home/testuser/.ssh/id_rsa): 

Accept the default by hitting the Return key

Generate an SSH Key (2)

Created directory '/home/testuser/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/testuser/.ssh/id_rsa
Your public key has been saved in /home/testuser/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:<very-long-hash> testuser@mac3
The key's randomart image is:
+---[RSA 3072]----+
|          .o o...|
|            +  ..|
|           o+....|
|        .. .+*...|
|       oS . o++. |
|  . E  oo. = o= +|
|   o  .o+.+.A. B.|
|    ... oo.+.+o o|
|    ..  .++.. .o.|
+----[SHA256]-----+
testuser@mac3:~$ 

Generate an SSH Key (3)

The command

ls ~/.ssh

should now return the files containing the private and the public SSH key:

id_rsa  id_rsa.pub

How Do We Use git?

The git Workflow—An Overview

  1. Create a Working Directory (read https://s.gwdg.de/gufGgi for naming conventions)
  2. Create a Repository
  3. Create or change an existing file
  4. Add the file’s current status to the Staging Area
  5. Commit to Repository
  6. Repeat from 3

---
config:
  look: handDrawn
---
flowchart TB
    a["Create Working 
    Directory"] --> b["Create a
    Repository"]
    b --> c["Create/change
    file"]
    c --> d["Add to Staging
    Area (Index)"]
    d --> c
    d --> e["Commit to Repo"]
    e --> c

End of Part 1

Thank you for your attention!