Skip to main content
Techlogia — AI and Web Development Berlin

Practise this module for free on a real VM

Sign up for free
 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).
  • Branch: a line of development; the main branch is usually called main today.
  • 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/. git status shows you where you stand after every step.

How the checker works

It looks directly into your repository (read-only): whether it exists, which branch you are on, which files Git knows and which commits exist. You do not need to copy any output into files.

Your goal

You create a repo, rename the branch, add a file, make your first commit and build a small 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).

    mkdir -p /home/student/git-uebung && cd /home/student/git-uebung
    git init
    git status

    Check: git status in the folder /home/student/git-uebung reports No commits yet instead of not a git repository. The checker looks directly into your repository.

  2. 2. Read and rename the branch

    Concept: branch. The first line of git status tells you which branch (line of development) you are on — in a fresh repo often master. Many projects call the main branch main today. Rename it and check the result:

    cd /home/student/git-uebung
    git status
    git branch -m main
    git status

    Check: git status starts with On branch main.

  3. 3. Track a file

    Concept: staging with git add. Before a file goes into a commit, you must "stage" it — Git then keeps it ready. Create a file, stage it and look at the status each time:

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

    Before git add, hallo.txt is listed under Untracked files, afterwards under Changes to be committed.

    Check: git status lists hallo.txt under Changes to be committed.

  4. 4. Make your first commit

    Concept: commit. A commit saves the staged changes as a snapshot with a description (-m). Git wants to know who makes the commit — set your name and email once (a made-up address is fine):

    cd /home/student/git-uebung
    git config --global user.name "Your Name"
    git config --global user.email "you@example.org"
    git commit -m "first commit"

    Check: git log --oneline shows a line like 1a2b3c4 first commit.

  5. 5. Second commit and history

    Concept: commit history. Every commit attaches to the previous one — that is how the history grows. Change hallo.txt, commit the change and look at the history:

    cd /home/student/git-uebung
    echo "second line" >> hallo.txt
    git commit -am "second commit"
    git log --oneline

    -a automatically includes all known, changed files. With --oneline you get one line per commit: the shortened commit ID (hash) plus the message.

    Check: git log --oneline shows at least two commits.

Knowledge check: Git basics

No VM, about 3 minutes. You recall what you practised in this module – wrong answers come back once more at the end.

Related courses

Now practice it yourself

Reading is good – doing is better. Practise this module 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?