Basic Operations Exercises

Hands-on practice with fundamental Git operations

Learning Objectives

  • Apply your knowledge of Git repository initialization and configuration
  • Practice the basic Git workflow with real-world scenarios
  • Master file staging and commit operations
  • Implement effective .gitignore patterns for different project types

Practice Overview

Welcome to the practical exercises for basic Git operations. These exercises will help reinforce your understanding of fundamental Git concepts through hands-on practice. Each exercise includes step-by-step instructions and validation criteria to ensure you're on the right track.

Exercise 1: Repository Setup

Scenario

You're starting a new project called "recipe-collection". Create a Git repository and set it up with proper configuration.

Steps:

  1. Create a new directory called "recipe-collection"
  2. Initialize it as a Git repository
  3. Configure your name and email for this repository
  4. Create a README.md file with a project description
  5. Make your first commit

Solution:

Repository Setup Commands
# Create and enter directory
$ mkdir recipe-collection
$ cd recipe-collection
# Initialize repository
$ git init
# Configure user information
$ git config user.name "Your Name"
$ git config user.email "your.email@example.com"
# Create README file
$ echo "# Recipe Collection
A digital collection of favorite recipes." > README.md
# Make first commit
$ git add README.md
$ git commit -m "Initial commit: Add README"

Validation Checklist:

  • Directory contains a .git folder
  • Git configuration shows correct user info
  • Repository has at least one commit

Exercise 2: Basic Workflow

Scenario

Add three recipe files to your collection and practice the basic Git workflow of staging and committing changes.

Steps:

  1. Create three .md files for different recipes
  2. Stage the files individually
  3. Check status between operations
  4. Make meaningful commits for each recipe
  5. Review your commit history

Sample Solution:

Basic Workflow Commands
# Create recipe files
$ echo "# Chocolate Cake Recipe" > chocolate-cake.md
$ echo "# Pasta Carbonara Recipe" > carbonara.md
$ echo "# Garden Salad Recipe" > garden-salad.md
# Stage and commit files individually
$ git add chocolate-cake.md
$ git commit -m "Add chocolate cake recipe"
$ git add carbonara.md
$ git commit -m "Add pasta carbonara recipe"
$ git add garden-salad.md
$ git commit -m "Add garden salad recipe"
# Check history
$ git log --oneline

Exercise 3: .gitignore Configuration

Scenario

Configure your repository to ignore certain files and directories commonly excluded in recipe management systems.

Requirements:

  • Ignore all image files in a future 'images' directory
  • Ignore temporary files ending with .tmp
  • Ignore a local notes directory
  • Ignore OS-specific files

Solution:

.gitignore file
# Recipe project .gitignore
# Image files
images/
# Temporary files
*.tmp
# Local notes
notes/
# OS-specific files
.DS_Store
Thumbs.db
# Editor directories
.vscode/
.idea/

Test Your Configuration:

Testing .gitignore
# Create test files
$ mkdir images notes
$ touch images/test.jpg notes/ideas.txt
$ touch temp.tmp
# Check if files are ignored
$ git status
# Test adding ignored files
$ git add .
$ git status

Practice Tips

  • Use git status frequently to monitor your repository's state
  • Write clear, descriptive commit messages that explain what changes were made
  • If you make a mistake, don't worry! Use git log andgit reset to recover