0
0
Gitdevops~15 mins

How files move between three areas in Git - Try It Yourself

Choose your learning style9 modes available
How files move between three areas in Git
📖 Scenario: You are working on a simple project using Git. You want to understand how files move between the three main areas in Git: the working directory, the staging area (index), and the repository (commit history).
🎯 Goal: Learn how to create a file, add it to the staging area, and commit it to the Git repository. This will help you understand the flow of files in Git.
📋 What You'll Learn
Create a new file called example.txt with some text
Add the file example.txt to the Git staging area using git add
Commit the staged file with the message Initial commit of example.txt
Show the commit log to verify the commit
💡 Why This Matters
🌍 Real World
Understanding how files move between the working directory, staging area, and repository is essential for managing changes in any software project using Git.
💼 Career
This knowledge is fundamental for developers, DevOps engineers, and anyone working with version control systems to collaborate and track code changes effectively.
Progress0 / 4 steps
1
Create a new file in the working directory
Create a file called example.txt in your working directory with the content Hello, Git! using the command echo "Hello, Git!" > example.txt.
Git
Need a hint?

Use the echo command to write text into a file.

2
Add the file to the Git staging area
Use the command git add example.txt to add the file example.txt to the Git staging area.
Git
Need a hint?

The git add command moves files from the working directory to the staging area.

3
Commit the staged file to the repository
Commit the staged file using the command git commit -m "Initial commit of example.txt" to save it in the Git repository.
Git
Need a hint?

The git commit command saves the staged changes to the repository with a message.

4
Show the commit log
Use the command git log --oneline to display the commit history and verify your commit.
Git
Need a hint?

The git log --oneline command shows a short summary of commits.