Git Repository Initialization Quiz
Master the foundational step of every Git project. This quiz covers creating repositories, understanding the .git directory, tracking your first files, and making that all-important initial commit.
Question 1
You have just run `git init` in a project directory. You notice a hidden folder named `.git` has been created. Which of the following best describes the critical role of this specific directory?
Question 2
You are starting a new project and want to initialize a Git repository specifically in a new subfolder named 'my-app', rather than the current directory. Which command achieves this directly?
# Current location: /home/user/projects
$ pwd
/home/user/projects
Question 3
After initializing a repository, you create a file named `README.md`. You run `git status` and see it listed under 'Untracked files'. What does this status imply about the file?
Question 4
Review the following terminal session. You have initialized a repository and created a file, but the commit fails. Why does the `git commit` command return an error?
$ git init
Initialized empty Git repository in /project/.git/
$ echo "Hello World" > main.py
$ git commit -m "Initial commit"
On branch main
Initial commit
nothing to commit (create/copy files and use "git add" to track)
Question 5
You want to add all files in the current directory to the staging area for the initial commit, including files in subdirectories. Which command is the standard way to achieve this?
Question 6
Inside the `.git` directory, there is a file named `HEAD`. In a freshly initialized repository with no commits yet, what is the role of this file?
Question 7
You run `git status` and see the following output. What does the section 'Changes to be committed' represent?
$ git status
On branch main
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: app.js
new file: style.css
Question 8
Why is the first commit in a repository (often called the 'root commit') special compared to all subsequent commits?
Question 9
You have initialized a repository and want to ignore a temporary folder named `temp/`. You create a `.gitignore` file. For this to work effectively from the start, what should you do?
$ git init
$ echo "temp/" > .gitignore
$ mkdir temp
$ touch temp/cache.log
Question 10
Consider the following scenario. You accidentally run `git init` in your home directory (`~`) instead of your project folder. What is the safest way to undo this?
Question 11
You run `git status` and see 'nothing to commit, working tree clean'. What does this indicate?
Question 12
Which of the following commands creates a new Git repository in the current directory?
Question 13
You are curious about the internals of Git and decide to rename the `.git` folder to `.git_backup`. What will happen when you subsequently run `git status` in that directory?
Question 14
When you run `git add file.txt`, Git stores the content of that file in the staging area. Where is this staging data physically stored on your disk?
Question 15
You want to create a central repository on a server that will only be used for pushing and pulling, not for direct editing. Which command initializes such a repository?
$ ssh user@server
$ mkdir project.git
$ cd project.git
$ # Which command goes here?
Question 16
You have an existing project that was already initialized with Git years ago. If you accidentally run `git init` again inside this directory, what happens?
Question 17
You want to ensure that every new repository you create uses 'main' as the default branch name instead of 'master'. Which command sets this configuration globally?
Question 18
You have deleted a file named `old_logo.png` from your file system. You want to stage this deletion so it is included in the next commit. Which command does this?
Question 19
You create an empty directory named `logs/` to store future log files. You run `git add .` and `git status`. Why does the `logs/` directory not appear in the status?
Question 20
You are initializing a repository and want to selectively stage only *parts* of a file for the first commit (e.g., you wrote a lot of code but only want to commit the header). Which command allows this?
Question 21
Inside `.git/config`, you see a setting `[core] bare = false`. What does this specific setting indicate?
Question 22
You have just installed Git on a new machine. Before initializing your first repository, what is the *most* important configuration step to ensure your commits are attributed correctly?
$ git config --global user.name "Your Name"
$ git config --global user.email "[email protected]"
Question 23
You want to create a commit to start your repository history, but you don't have any files ready yet. You just want to establish the root of the history. How can you create an empty commit?
Question 24
In the output of `git log`, you see 'Author' and 'Date'. Is it possible for the 'Author' of a commit to be different from the person who actually committed it (the 'Committer')?
Question 25
You run `git status -s` (short format) and see `?? file.txt`. What does the `??` symbol mean?
