Bird
Raised Fist0
Gitdevops~20 mins

Creating a repository with git init - 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 Init Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
1:30remaining
What is the output of git init in a new directory?
You run git init inside an empty folder. What message does Git show?
Git
git init
Afatal: Not a git repository (or any of the parent directories): .git
BInitialized empty Git repository in /path/to/directory/.git/
CError: Repository already exists
DNothing to commit, working tree clean
Attempts:
2 left
💡 Hint
Think about what Git says when it creates a new repository folder.
🧠 Conceptual
intermediate
1:30remaining
What does git init actually do?
Choose the correct description of what git init does when run in a folder.
ACreates a new hidden .git directory to track changes in the folder
BMerges the current folder with another Git repository
CDeletes all files in the folder and starts fresh
DUploads the folder contents to a remote Git server
Attempts:
2 left
💡 Hint
Think about what Git needs to track changes locally.
Troubleshoot
advanced
2:00remaining
Why does git init fail with 'Permission denied'?
You try to run git init in a folder but get this error:
fatal: could not create work tree dir 'folder': Permission denied
What is the most likely cause?
AThe folder is already a Git repository
BGit is not installed on your system
CYou do not have write permission for the folder
DYou forgot to run <code>git clone</code> first
Attempts:
2 left
💡 Hint
Think about what 'Permission denied' means in file systems.
🔀 Workflow
advanced
2:00remaining
What is the correct sequence to create and start tracking files with Git?
You want to start a new project folder and track files with Git. Which sequence of commands is correct?
Acd project; mkdir project; git init; git commit -m 'first commit'; git add .
Bgit init; mkdir project; cd project; git add .; git commit -m 'first commit'
Cmkdir project; git init; git add .; cd project; git commit -m 'first commit'
Dmkdir project; cd project; git init; git add .; git commit -m 'first commit'
Attempts:
2 left
💡 Hint
You must create and enter the folder before initializing Git there.
Best Practice
expert
2:30remaining
Which practice is best when initializing a Git repository for a new project?
You start a new project and run git init. What should you do next to avoid committing unwanted files?
ACreate a .gitignore file listing files and folders to exclude before adding files
BImmediately commit all files without filtering
CRun <code>git clone</code> to copy files from a remote repo
DDelete all hidden files before committing
Attempts:
2 left
💡 Hint
Think about how to prevent temporary or sensitive files from being tracked.

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

  1. 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.
  2. Step 2: Identify what git init does not do

    It does not delete files, upload data, or merge branches automatically.
  3. Final Answer:

    It creates a new Git repository by adding a hidden .git folder. -> Option A
  4. Quick Check:

    git init creates .git folder = A [OK]
Hint: Remember: git init creates .git folder to start tracking [OK]
Common Mistakes:
  • Thinking git init deletes files
  • Confusing git init with git clone
  • Assuming git init uploads files
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

  1. Step 1: Recall the Git command to start a repository

    The correct command to initialize a Git repository is git init.
  2. Step 2: Verify other options

    Commands like git start, git create, and git new do not exist in Git.
  3. Final Answer:

    git init -> Option A
  4. 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

  1. Step 1: Understand what git init creates

    Running git init creates a hidden .git folder inside the current directory.
  2. 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.
  3. Final Answer:

    . .. .git -> Option D
  4. 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

  1. Step 1: Check permissions for creating .git folder

    If the folder does not allow writing, git init cannot create the hidden .git directory.
  2. 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.
  3. Final Answer:

    You ran git init inside a folder without write permission. -> Option C
  4. 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?
hard
A. git init; git commit -m "Initial commit"; git add .
B. git init; git add .; git commit -m "Initial commit"
C. git clone; git add .; git commit -m "Initial commit"
D. git add .; git init; git commit -m "Initial commit"

Solution

  1. Step 1: Initialize the Git repository

    Use git init to create the repository in the existing folder.
  2. Step 2: Add all files to staging area

    Use git add . to stage all files for commit.
  3. Step 3: Commit the staged files

    Use git commit -m "Initial commit" to save the snapshot.
  4. Final Answer:

    git init; git add .; git commit -m "Initial commit" -> Option B
  5. Quick Check:

    Init, add, then commit = C [OK]
Hint: Always init first, then add files, then commit [OK]
Common Mistakes:
  • Running git commit before git add
  • Using git clone instead of git init for existing folder
  • Adding files before initializing repo