Skip to main content
Techlogia — AI and Web Development Berlin
All courses
Free to read – no sign-up

Git Basics

Understand version control with git. Run real git commands and save the output to a file as evidence.

Duration: 25 minLevel: BeginnerExercises: 5

Your first git commits

Git basics: your first commits

Git is the standard tool for version control of code: it stores snapshots of your files so you can trace and roll back every change. Every developer uses it daily.

Key terms

  • Repository (repo): a project folder managed by Git (git init creates it).
  • Staging (git add): you choose which changes go into the next snapshot.
  • Commit (git commit): a saved snapshot with a description.
  • Log (git log): the list of all commits.

Work in the folder /home/student/git-uebung/. In this lesson you save the output of each command into a stepN/schrittN.txt file as proof.

Your goal

You create a repo, add a file, make your first commit and view the history.

Exercises

  1. 1. Initialize a repository

    Concept: initialise a repository. git init turns a normal folder into a Git repository (it creates a hidden .git folder). Save the output as proof.

    mkdir -p /home/student/git-uebung && cd /home/student/git-uebung
    git init > schritt1.txt
    cat schritt1.txt

    Check: schritt1.txt contains the word Initialized (from "Initialized empty Git repository").

  2. 2. Status of an empty repo

    Concept: git status. git status shows the current state: which branch you are on and what changes exist. In a fresh repo everything is "clean".

    cd /home/student/git-uebung
    git status > schritt2.txt
    cat schritt2.txt

    Check: schritt2.txt contains branch or commit (from the status output).

  3. 3. Track a file

    Concept: staging with git add. Before a file goes into a commit, you must "stage" it. Create a file, stage it, and record the status.

    cd /home/student/git-uebung
    echo "hello" > hallo.txt
    git add hallo.txt
    git status > schritt3.txt
    cat schritt3.txt

    Check: schritt3.txt mentions hallo.txt (as a staged file).

  4. 4. Make your first commit

    Concept: commit. A commit saves the staged changes as a snapshot with a description (-m). Use the message first commit.

    cd /home/student/git-uebung
    git -c user.email=student@lab -c user.name=Student commit -m "first commit" > schritt4.txt
    cat schritt4.txt

    The -c user.... options set name/email for the commit once (otherwise Git complains).

    Check: schritt4.txt contains first commit.

  5. 5. Show the commit log

    Concept: commit history. git log shows all commits. With --oneline you get one line per commit: the shortened commit ID (hash) plus the message.

    cd /home/student/git-uebung
    git log --oneline > schritt5.txt
    cat schritt5.txt

    Check: schritt5.txt contains a line with a hash (at least 7 chars) followed by text.

Related courses

Now practice it yourself

Reading is good – doing is better. Start this course on a real Linux VM, right in your browser. A free account is all it takes.

Start for free

Lab content under CC BY 4.0 – free to use with attribution (© TechLogia).

How do you like this page?

Git Basics | Techlogia Lab