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
Creating a repository with git init
📖 Scenario: You want to start a new project on your computer and keep track of all your changes using Git. This helps you save different versions of your work and share it with others later.
🎯 Goal: You will create a new folder for your project and turn it into a Git repository using the git init command. This sets up Git to track your files.
📋 What You'll Learn
Create a new directory called my_project
Navigate into the my_project directory
Initialize a Git repository inside my_project using git init
Verify the repository was created by checking the Git status
💡 Why This Matters
🌍 Real World
Developers use Git repositories to save and manage changes in their projects, making teamwork and version control easier.
💼 Career
Knowing how to initialize a Git repository is a fundamental skill for software developers, DevOps engineers, and anyone working with code.
Progress0 / 4 steps
1
Create a new directory called my_project
Type the command to create a new directory named my_project.
Git
Hint
Use the mkdir command followed by the folder name.
2
Navigate into the my_project directory
Type the command to change your current directory to my_project.
Git
Hint
Use the cd command followed by the folder name.
3
Initialize a Git repository inside my_project
Type the command git init to create a new Git repository in the current directory.
Git
Hint
Simply type git init to start tracking your project with Git.
4
Check the Git repository status
Type the command git status to see the current state of your Git repository.
Git
Hint
Use git status to see if Git is tracking your folder.
Practice
(1/5)
1. What does the command git init do in a folder?
easy
A. It creates a new Git repository by adding a hidden .git folder.
B. It deletes all files in the folder.
C. It uploads the folder to a remote server.
D. It merges two branches automatically.
Solution
Step 1: Understand the purpose of git init
The command git init starts a new Git repository in the current folder by creating a hidden .git directory.
Step 2: Identify what git init does not do
It does not delete files, upload data, or merge branches automatically.
Final Answer:
It creates a new Git repository by adding a hidden .git folder. -> Option A
2. Which of the following is the correct syntax to initialize a Git repository in the current directory?
easy
A. git init
B. git start
C. git create
D. git new
Solution
Step 1: Recall the Git command to start a repository
The correct command to initialize a Git repository is git init.
Step 2: Verify other options
Commands like git start, git create, and git new do not exist in Git.
Final Answer:
git init -> Option A
Quick Check:
Initialize repo command = git init = A [OK]
Hint: Use 'git init' exactly to start a repo [OK]
Common Mistakes:
Typing git start instead of git init
Using git create or git new which are invalid
Adding extra words after git init
3. After running git init in an empty folder, what will be the output of ls -a?
medium
A. . .. .gitignore
B. . ..
C. . .. .git .gitignore
D. . .. .git
Solution
Step 1: Understand what git init creates
Running git init creates a hidden .git folder inside the current directory.
Step 2: List all files including hidden ones
The command ls -a shows all files including hidden ones like ., .., and .git. Since the folder is empty except for .git, only these appear.
Final Answer:
. .. .git -> Option D
Quick Check:
git init creates .git folder only = B [OK]
Hint: ls -a shows .git folder after git init [OK]
Common Mistakes:
Expecting .gitignore to appear automatically
Not including hidden files in listing
Confusing .git with other files
4. You ran git init but the .git folder is missing. What is the most likely reason?
medium
A. You ran git init but your folder is already a Git repository.
B. You forgot to install Git on your system.
C. You ran git init inside a folder without write permission.
D. You ran git init with a typo like git initt.
Solution
Step 1: Check permissions for creating .git folder
If the folder does not allow writing, git init cannot create the hidden .git directory.
Step 2: Evaluate other options
If Git was not installed, the command would fail with an error. A typo would cause a command not found error. If the folder was already a Git repo, .git would exist.
Final Answer:
You ran git init inside a folder without write permission. -> Option C
Quick Check:
Missing .git usually means no write permission = D [OK]
Hint: Check folder write permission if .git missing after init [OK]
Common Mistakes:
Assuming Git is not installed without checking error
Ignoring typos in command
Thinking .git disappears if repo exists
5. You want to start tracking an existing project folder with Git. Which sequence of commands correctly initializes the repository and adds all files for the first commit?