Git Repository Initialization Quiz

Git
0 Passed
0% acceptance

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.

25 Questions
~50 minutes
1

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?

A
It contains only the configuration files for your local user profile and nothing else.
B
It serves as a temporary cache for your files that is deleted after every commit.
C
It stores the entire history, configuration, and metadata of the repository, effectively acting as the database for Git.
D
It is a backup folder that stores a copy of your project files in case you accidentally delete them.
2

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?

bash

# Current location: /home/user/projects
$ pwd
/home/user/projects
          
A
git init my-app
B
git start my-app
C
mkdir my-app && git init
D
git new my-app
3

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?

A
The file has been ignored by a .gitignore file and will never be tracked.
B
Git sees the file in the working directory but is not yet tracking its changes or including it in the next commit.
C
The file is corrupt and Git cannot read its contents.
D
The file has been automatically added to the staging area but not yet committed.
4

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?

bash

$ 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)
          
A
You cannot commit to the 'main' branch immediately after initialization.
B
The commit message must be longer than two words.
C
You did not configure your user.name and user.email yet.
D
You did not stage the 'main.py' file using 'git add' before attempting to commit.
5

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?

A
git add .
B
git stage all
C
git commit --all
D
git push origin main
6

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?

A
It contains the first commit message.
B
It points to the current branch reference (usually refs/heads/main), even if that branch doesn't exist yet.
C
It stores the remote repository URL.
D
It is an empty file waiting for the first log entry.
7

Question 7

You run `git status` and see the following output. What does the section 'Changes to be committed' represent?

bash

$ 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
          
A
These files have been committed to the repository history.
B
These files are in the Staging Area (Index) and are ready to be included in the next commit.
C
These files are untracked and Git is ignoring them.
D
These files have been modified but not yet added to the stage.
8

Question 8

Why is the first commit in a repository (often called the 'root commit') special compared to all subsequent commits?

A
It is the only commit that can be modified without issues.
B
It has no parent commit, marking the beginning of the project's history graph.
C
It must always contain a README file.
D
It does not have a SHA-1 hash.
9

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?

bash

$ git init
$ echo "temp/" > .gitignore
$ mkdir temp
$ touch temp/cache.log
          
A
Run `git add temp/` to force Git to ignore it.
B
Commit the `.gitignore` file so the ignore rules are tracked and shared.
C
Nothing, Git automatically detects `.gitignore` and hides it from status.
D
Run `git config --global core.excludesfile .gitignore`.
10

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?

A
Run `git uninit`.
B
Delete the `.git` directory from your home folder.
C
Run `git reset --hard`.
D
Run `rm -rf *` in your home directory.
11

Question 11

You run `git status` and see 'nothing to commit, working tree clean'. What does this indicate?

A
You have not initialized a repository yet.
B
All files in your directory are tracked, and there are no modified or staged changes pending.
C
You have deleted all files in the directory.
D
Git has stopped tracking your files due to an error.
12

Question 12

Which of the following commands creates a new Git repository in the current directory?

A
git create
B
git start
C
git init
D
git new
13

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?

A
Git will automatically detect the rename and function normally.
B
Git will report 'fatal: not a git repository' because it cannot find the .git directory.
C
Git will ask you to point to the new location of the repository metadata.
D
Git will immediately create a new empty .git directory.
14

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?

A
In a hidden file named `.staging` in your user's home directory.
B
In the system's temporary folder (e.g., /tmp).
C
Inside the `.git` directory, primarily in the `index` file and `objects` folder.
D
It is kept in RAM only until you commit.
15

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?

bash

$ ssh user@server
$ mkdir project.git
$ cd project.git
$ # Which command goes here?
          
A
git init --server
B
git init --bare
C
git init --central
D
git init --remote
16

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?

A
It deletes the existing history and starts fresh.
B
It throws a fatal error and stops.
C
It safely re-initializes the repository, picking up new templates but keeping your existing history and config intact.
D
It creates a nested `.git` folder inside the existing `.git` folder.
17

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?

A
git config --global init.defaultBranch main
B
git init --default main
C
git branch -m main
D
git config --global core.branch main
18

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?

A
git add old_logo.png
B
git rm old_logo.png
C
git add .
D
All of the above can work depending on the context.
19

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?

A
Git does not track empty directories.
B
You need to run `git add --dir logs/`.
C
Directories are only tracked if they are listed in .gitignore.
D
It takes a few minutes for Git to index new folders.
20

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?

A
git add --partial
B
git add -p
C
git commit --select
D
git stage --chunk
21

Question 21

Inside `.git/config`, you see a setting `[core] bare = false`. What does this specific setting indicate?

A
The repository is empty.
B
The repository has a working directory where you can edit files.
C
The repository is not connected to a remote server.
D
The repository allows anonymous push access.
22

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?

bash

$ git config --global user.name "Your Name"
$ git config --global user.email "[email protected]"
          
A
Setting the default text editor.
B
Setting the user.name and user.email.
C
Generating an SSH key.
D
Creating a GitHub account.
23

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?

A
git commit -m 'Root'
B
git commit --allow-empty -m 'Root commit'
C
git commit --void
D
You cannot create a commit without files.
24

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')?

A
No, they are always the same person.
B
Yes, for example when re-writing history or applying patches from someone else.
C
Only in bare repositories.
D
Yes, but only if you use two different email addresses.
25

Question 25

You run `git status -s` (short format) and see `?? file.txt`. What does the `??` symbol mean?

A
The file is missing.
B
The file is untracked.
C
The file has a merge conflict.
D
The file is staged but modified.