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:
- Create a new directory called "recipe-collection"
- Initialize it as a Git repository
- Configure your name and email for this repository
- Create a README.md file with a project description
- Make your first commit
Solution:
# 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:
- Create three .md files for different recipes
- Stage the files individually
- Check status between operations
- Make meaningful commits for each recipe
- Review your commit history
Sample Solution:
# 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:
# Recipe project .gitignore # Image filesimages/ # Temporary files*.tmp # Local notesnotes/ # OS-specific files.DS_StoreThumbs.db # Editor directories.vscode/.idea/
Test Your Configuration:
# 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