Intro to git

Block 1.1: What is git?

Jan Simson

Background: https://unsplash.com/photos/842ofHC6MaI

What is git?

  • Version Control System (VCS)
    • Looks at the changes in your files
    • Records all changes over time to give you a full history
    • Similar to “track changes” in Microsoft Word / LibreOffice

Git only looks at and tracks the changes in a file

What is git? Strengths & Weaknesses

  • Strengths 💪
    • Very hard to lose files with git
    • Great for collaboration
    • Fast (like, really fast)
    • History allows you to go back and understand changes or revert when there are problems
    • Reproducibility

What is git? Strengths & Weaknesses

  • Weaknesses 😢
    • Can be a bit complicated to use (esp. at first)
    • History takes up file space (but only little)
    • Struggles with binary (i.e. non-text) files
    • Struggles with large files
      • Not good for storing data!
    • You do need to explicitly use it i.e. it doesn’t just work in the background

CLI vs. GUI?!

Git can be used via both a CLI and GUI.

Command Line Interface (CLI)

  • Also Console or Terminal
  • Only text
  • You type your command, press enter and receive back text
  • Very flexible, but a bit unintuitive

Graphical User Interface (GUI)

  • Most applications nowadays
  • Often asier to use
  • Typically mainly controlled via your Mouse
  • Buttons and other clickable elements

CLI vs. GUI?!

An example of using git in a command line interface (CLI)

An example of using git in SourceTree, a graphical user interface (GUI)

CLI vs. GUI: git

*: These programs have a different main purpose, but also offer the option of using git via their GUI.

Using the git CLI

  • We will first use git via its CLI (i.e. in the Terminal).
    • On windows, open Git Bash (start menu -> Git Bash).
    • On MacOS, open the Terminal app.
    • On Linux, open your distribution’s (or any other) terminal emulator.
  • Let’s do this together now!

Using the git cheatsheet to follow along

  • There are many existing cheatsheets out there with the most important git commands
  • In this course we will be using the one from GitHub Education to help you navigate the course

Let’s Set Things Up: git config ⚙️

Run the following commands in your terminal to correctly configure git on your computer.

# Add your name
git config --global user.name "Your Name"

# Add your email address
git config --global user.email "your.email@kit.edu"

# Use modern main branch name
git config --global init.defaultbranch main

Let’s Set Things Up: git config ⚙️

For Linux/Mac:

git config --global core.autocrlf input

For Windows:

git config --global core.autocrlf true

Why? Windows saves linebreaks (enter) differently then Linux/Mac does 🤷‍♂️

Getting started with git (for real)

Background: Warnerbros, via Digital Spy

See what’s happening: git status

A project in git is called a repository (or repo for short) and it always corresponds to a directory on your machine.

To see the current status of a git repository you can run the status command.

git status

See what’s happening: git status

git status
# fatal: not a git repository (or any of the parent directories): .git

We get an error here, because you first need to initialize a git repository.

Initializing a repository: git init

Before we can use git in a project we first have to initialize it in the directory of the project. This is done via the init command.

git init
# Initialized empty Git repository in /Users/jan/Dev/temp/test/.git/

git status
# On branch main
# No commits yet
# nothing to commit (create/copy files and use "git add" to track)

With git init we turn the directory into a repository.

Practical: init

  1. Identify the filepath of the directory you created earlier.
  2. Open the Terminal (or Git Bash on Windows) in VS Code
  3. Use git init to initialize a new repository there
  4. Keep VS Code open in this directory for later

Downloading a repository: git clone

Alternatively, we can download a repository from the internet using the clone command. This will create a new repository on our machine and fill it with the remote repository’s contents.

git clone https://github.com/open-teaching/git-murder-mystery.git

End of Section 🎉

Any Questions?

[🏡 Back to Overview]

[⏩️ Next Section]