Skip to Main Content






Git Basics

Interactive Exercises

Interactive exercises are crucial for reinforcing the concepts covered in the workshop. You will get hands-on experience with Git by creating repositories, making commits, branching, and merging.

These exercises are designed to build confidence with Git's core features. You will be able to experiment beyond the guided steps, as hands-on practice is key to mastering version control with Git.

Before you proceed

Note on System Requirements and Prerequisites

Before beginning these exercises, ensure you have the following:

  • Software Requirements:

    • A computer with Git installed. If Git is not installed, follow the installation instructions specific to your operating system at the following link: Git Install
  • Previous Coding Knowledge:

    • Basic familiarity with command-line interfaces (CLI) is helpful but not required.
    • Basic understanding of version control concepts is recommended.

Exercise 1: Creating a Repository

Exercise 1: Creating a Repository

  • Objective: Create a new Git repository and understand the basic setup.

  • Steps:

    1. Navigate to your project directory:

      cd path/to/your/project

    2. Initialize a Git repository:

      git init

    3. Check the repository status:

      git status

  • Outcome: You will have a new Git repository initialized in your project directory.

Exercise 2: Making Commits

  • Objective: Stage files and create commits to track changes in the repository.

  • Steps:

    1. Create a new file:

      echo "Hello, Git!" > hello.txt

    2. Stage the file for commit:

      git add hello.txt

    3. Commit the changes:

      git commit -m "Add hello.txt file"

  • Outcome: You will have created and committed changes to your repository.

Exercise 3: Branching

  • Objective: Create a new branch and switch between branches.

  • Steps:

    1. Create a new branch:

      git branch landing-page

    2. Switch to the new branch:

      git checkout landing-page

    3. Make changes in the new branch:
      • Modify hello.txt or create a new file.
    4. Commit the changes:

      git commit -am "Make changes in landing-page"

  • Outcome: You will understand how to create and work within different branches.

Exercise 4: Merging Branches

  • Objective: Merge changes from one branch into another and resolve any conflicts that may arise.

  • Steps:

    1. Switch back to the main branch:

      git checkout main

    2. Merge the feature branch into the main branch:

      git merge landing-page

    3. Resolve any merge conflicts (if applicable):
      • If conflicts occur, Git will prompt you to resolve them manually. Once resolved, commit the merged changes:

      git add .
      git commit -m "Resolve merge conflicts and merge landing-page"

  • Outcome: You will gain experience in merging branches and handling conflicts.