0
0
Gitdevops~15 mins

git add with patterns and directories - Mini Project: Build & Apply

Choose your learning style9 modes available
Using git add with Patterns and Directories
📖 Scenario: You are working on a project with multiple files and folders. You want to prepare specific files and folders to be saved in your next snapshot (commit) using git add. This helps you control exactly what changes you include.
🎯 Goal: Learn how to use git add with file name patterns and directory names to stage files for commit.
📋 What You'll Learn
Create a directory structure with files
Use git add with a pattern to add specific files
Use git add with a directory name to add all files inside
Display the list of staged files
💡 Why This Matters
🌍 Real World
Developers often need to add only certain files or folders to their git commits to keep changes organized and meaningful.
💼 Career
Knowing how to use git add with patterns and directories is essential for version control in software development and DevOps workflows.
Progress0 / 4 steps
1
Create files and directories
Create a directory called project. Inside project, create three files named index.html, style.css, and script.js. Also create a subdirectory called docs inside project with a file named readme.md.
Git
Need a hint?

Use mkdir -p to create directories and touch to create empty files.

2
Initialize git and add CSS files
Inside the project directory, initialize a new git repository with git init. Then use git add with a pattern to add only the .css files to the staging area.
Git
Need a hint?

Use git add *.css to add all CSS files in the current directory.

3
Add the docs directory
Use git add with the directory name docs to add all files inside the docs folder to the staging area.
Git
Need a hint?

Use git add docs to add all files inside the docs directory.

4
Show staged files
Use git status --short to display the list of files currently staged for commit.
Git
Need a hint?

The output should list style.css and docs/readme.md as staged files.