This hands-on exercise guides you through creating your first Git repository, adding files, and committing them. You will learn the fundamental Git workflow.Setting Up Your ProjectFirst, you need a place for your project to live. Open your terminal or command prompt. Create a new directory for this practice session and navigate into it:mkdir my-git-project cd my-git-projectThis directory, my-git-project, is currently just a regular folder. Git isn't tracking anything inside it yet.Initializing the RepositoryNow, let's turn this directory into a Git repository. Use the git init command:git initYou should see output similar to this:Initialized empty Git repository in /path/to/your/my-git-project/.git/This command creates a hidden subdirectory named .git. This .git directory contains all the necessary files and metadata for your repository, including the history, configuration, and object database. You typically won't need to interact with the .git directory directly.Checking the StatusLet's see what Git thinks about our new repository. Use the git status command:git statusThe output will look something like this:On branch main No commits yet nothing to commit (create/copy files and use "git add" to track)This tells us several things:We are on the main branch (this might be master on older Git versions, but main is the modern default).There are no commits in the repository's history yet.The working directory is clean relative to the repository. There are no tracked files with changes, and no new files have been staged.Creating and Staging a FileLet's create our first project file. Use your preferred text editor or a command like echo to create a simple README.md file:# Using echo (on Linux/macOS/Git Bash) echo "# My Awesome Project" > README.md # Or create the file manually with a text editor and add some text.Now, run git status again:git statusThe output has changed:On branch main No commits yet Untracked files: (use "git add <file>..." to include in what will be committed) README.md nothing added to commit but untracked files present (use "git add" to track)Git sees the new README.md file but tells us it's "untracked". This means the file exists in your working directory, but Git isn't tracking its history yet.To start tracking the file and prepare it for the next commit, we need to add it to the staging area using git add:git add README.mdThis command tells Git, "I want to include the current state of README.md in the next snapshot (commit)."Let's check the status one more time:git statusThe output now shows:On branch main No commits yet Changes to be committed: (use "git rm --cached <file>..." to unstage) new file: README.mdREADME.md is now listed under "Changes to be committed". It has been moved from the working directory status (untracked) into the staging area.Here's a simple visualization of the states you've just experienced:digraph GitWorkflow { rankdir=LR; node [shape=box, style=rounded, fontname="Arial", fontsize=10]; edge [fontname="Arial", fontsize=10]; "Working Directory" -> "Staging Area" [label="git add"]; "Staging Area" -> "Repository (.git)" [label="git commit"]; }Files move from the Working Directory to the Staging Area with git add, and then are saved permanently into the Repository history with git commit.Making Your First CommitThe file is staged and ready. Let's create the first snapshot of our project history using git commit. We'll use the -m flag to provide a descriptive commit message directly from the command line.git commit -m "Initial commit: Add README.md"You'll see output similar to this:[main (root-commit) abc1234] Initial commit: Add README.md 1 file changed, 1 insertion(+) create mode 100644 README.mdThis confirms that the commit was created.[main (root-commit) abc1234] indicates the branch (main), that it's the very first commit (root-commit), and the beginning of the unique commit hash (abc1234). Your hash will be different.The rest summarizes the changes included in this commit (1 file changed, 1 line inserted, README.md was created).Now, what does git status show?git statusOutput:On branch main nothing to commit, working tree cleanEverything is committed! Your working directory matches the latest snapshot stored in the repository, and the staging area is empty.Viewing the HistoryYou can see the commit you just made using git log:git logThe output will display details about your commit:commit abc1234567890def1234567890abcdef12345678 (HEAD -> main) Author: Your Name <your.email@example.com> Date: Mon Oct 26 10:30:00 2023 -0700 Initial commit: Add README.mdThis shows the full commit hash, the author and email (from your Git configuration), the date, and the commit message.Ignoring Files with .gitignoreOften, projects generate temporary files, logs, or build artifacts that you don't want to include in your Git history. Let's simulate this.Create a temporary file:echo "Temporary scratch notes" > notes.tmpCheck the status:git statusOn branch main Untracked files: (use "git add <file>..." to include in what will be committed) notes.tmp nothing added to commit but untracked files present (use "git add" to track)Git sees notes.tmp as untracked. To tell Git to ignore this file and any other files ending in .tmp, create a file named .gitignore (note the leading dot):echo "*.tmp" > .gitignoreThis creates the .gitignore file and adds a pattern *.tmp to it. The asterisk * acts as a wildcard, matching any sequence of characters.Now, check the status again:git statusOn branch main Untracked files: (use "git add <file>..." to include in what will be committed) .gitignore nothing added to commit but untracked files present (use "git add" to track)Notice that notes.tmp is no longer listed! Git is now ignoring it based on the rule in .gitignore. However, the .gitignore file itself is new and untracked. Since configuration like ignore rules should be part of your project history (so others using the repository benefit from them), let's add and commit it:git add .gitignore git commit -m "Add .gitignore to exclude temporary files"Check the status and log one last time:git status git loggit status should report nothing to commit, working tree clean. git log will now show two commits in your history.Congratulations! You have successfully initialized a Git repository, added files to the staging area, created commits to save snapshots of your project, and configured Git to ignore specific files. You've practiced the core workflow you'll use frequently when working with Git.