Bird
Raised Fist0
Gitdevops~20 mins

How files move between three areas in Git - Practice Exercises

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Git Area Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding Git's Three Areas

In Git, files move through three main areas: working directory, staging area, and repository. Which command moves changes from the working directory to the staging area?

Agit add
Bgit commit
Cgit clone
Dgit push
Attempts:
2 left
💡 Hint

Think about the command that prepares files for the next commit.

💻 Command Output
intermediate
2:00remaining
Result of git commit

What is the effect of running git commit -m 'message' after staging files?

ADeletes staged files
BMoves changes from working directory to staging area
CUploads changes to remote repository
DMoves staged changes to the repository area
Attempts:
2 left
💡 Hint

Consider what happens after files are staged and you want to save a snapshot.

🔀 Workflow
advanced
3:00remaining
Sequence of Commands to Move a File Through Git Areas

Which sequence of commands correctly moves a new file from creation to being saved in the local repository?

Agit commit >> git add >> git push
Bgit push >> git add >> git commit
Cgit add >> git commit >> git push
Dgit clone >> git add >> git commit
Attempts:
2 left
💡 Hint

Remember the order: stage, commit, then push.

Troubleshoot
advanced
2:30remaining
Why Changes Are Not Committed

You modified a file but after running git commit -m 'update', the changes are not saved in the repository. What is the most likely reason?

AYou forgot to run <code>git add</code> to stage the changes
BYou ran <code>git push</code> before <code>git commit</code>
CYou cloned the repository again
DYou deleted the file before committing
Attempts:
2 left
💡 Hint

Think about what prepares changes for commit.

Best Practice
expert
2:00remaining
Ensuring Changes Are Safely Stored Locally

Which command guarantees that your staged changes are saved permanently in your local Git repository?

Agit add
Bgit commit
Cgit push
Dgit status
Attempts:
2 left
💡 Hint

Consider which command creates a snapshot in your local repository.

Practice

(1/5)
1. Which command moves files from the working directory to the staging area in Git?
easy
A. git add
B. git commit
C. git push
D. git clone

Solution

  1. Step 1: Understand the role of git add

    The git add command moves files from the working directory to the staging area, preparing them for commit.
  2. Step 2: Differentiate from other commands

    git commit saves staged files to the local repository, git push sends commits to a remote, and git clone copies a repository.
  3. Final Answer:

    git add -> Option A
  4. Quick Check:

    Staging area update = git add [OK]
Hint: Add files to staging with git add [OK]
Common Mistakes:
  • Confusing git add with git commit
  • Thinking git push moves files locally
  • Using git clone to stage files
2. Which of these commands correctly saves staged files to the local repository?
easy
A. git commit -m "Save changes"
B. git status
C. git add .
D. git init

Solution

  1. Step 1: Identify the commit command

    git commit -m "message" saves the staged files into the local repository with a message.
  2. Step 2: Understand other commands

    git add . stages files, git status shows status, and git init creates a new repo.
  3. Final Answer:

    git commit -m "Save changes" -> Option A
  4. Quick Check:

    Save staged files = git commit [OK]
Hint: Commit staged files with git commit -m [OK]
Common Mistakes:
  • Using git add instead of git commit to save
  • Confusing git status with commit
  • Trying to commit without staging files
3. Given these commands run in order:
echo "Hello" > file.txt
git add file.txt
git commit -m "Add file"

Where is file.txt after these commands?
medium
A. Only in the working directory
B. In the local repository and working directory
C. Deleted from all areas
D. In the staging area only

Solution

  1. Step 1: Create and stage the file

    The file is created in the working directory, then moved to the staging area by git add.
  2. Step 2: Commit the file

    git commit saves the staged file to the local repository. The file remains in the working directory.
  3. Final Answer:

    In the local repository and working directory -> Option B
  4. Quick Check:

    Commit saves staged files, working files remain [OK]
Hint: Committed files stay in repo and working directory [OK]
Common Mistakes:
  • Thinking commit removes file from working directory
  • Believing staged files disappear after commit
  • Confusing staging area with repository
4. You ran git commit -m "Update" but Git says "nothing to commit". What is the likely cause?
medium
A. You committed files but did not push
B. You are in the wrong directory
C. You forgot to stage files with git add
D. You need to run git init again

Solution

  1. Step 1: Understand the message meaning

    "Nothing to commit" means no changes are staged for commit.
  2. Step 2: Identify missing staging step

    If you forgot git add, no files are staged, so commit has nothing to save.
  3. Final Answer:

    You forgot to stage files with git add -> Option C
  4. Quick Check:

    Stage files before commit = git add [OK]
Hint: Stage files first with git add before commit [OK]
Common Mistakes:
  • Thinking commit auto-stages files
  • Confusing push with commit
  • Assuming git init fixes this error
5. You edited app.js in your working directory. You want to save only this file to the local repository without including other changes. Which sequence of commands correctly moves app.js through Git's three areas?
hard
A. git add . then git commit -m "Save app.js"
B. git commit -m "Save app.js" then git add app.js
C. git push then git add app.js
D. git add app.js then git commit -m "Save app.js"

Solution

  1. Step 1: Stage the specific file

    Use git add app.js to move only app.js to the staging area.
  2. Step 2: Commit the staged file

    Run git commit -m "Save app.js" to save the staged changes to the local repository.
  3. Final Answer:

    git add app.js then git commit -m "Save app.js" -> Option D
  4. Quick Check:

    Stage then commit specific file = git add + git commit [OK]
Hint: Add specific file before commit to save only it [OK]
Common Mistakes:
  • Committing before adding files
  • Using git push instead of commit
  • Adding all files instead of just one