Bird
Raised Fist0
Gitdevops~10 mins

Creating a repository with git init - Interactive Practice

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
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the command to initialize a new Git repository.

Git
git [1]
Drag options to blanks, or click blank then click option'
Acommit
Binit
Cclone
Dpush
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'clone' instead of 'init' to create a new repository.
Trying to 'commit' before initializing the repository.
2fill in blank
medium

Complete the command to create a new directory and initialize a Git repository inside it.

Git
mkdir my_project && cd my_project && git [1]
Drag options to blanks, or click blank then click option'
Ainit
Bbranch
Cadd
Dstatus
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'status' which only shows repository status.
Using 'add' which stages files, not initializes.
3fill in blank
hard

Fix the error in the command to initialize a Git repository.

Git
git [1]
Drag options to blanks, or click blank then click option'
Aclone
Bcommit
Cinit
Dpush
Attempts:
3 left
💡 Hint
Common Mistakes
Typing 'git init init' which is invalid.
Confusing 'init' with other commands.
4fill in blank
hard

Fill both blanks to create a new directory and initialize a Git repository inside it.

Git
mkdir [1] && cd [2] && git init
Drag options to blanks, or click blank then click option'
AprojectX
Bmy_repo
Dyour_repo
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for creating and entering the directory.
Leaving one blank empty.
5fill in blank
hard

Fill all three blanks to initialize a Git repository, add all files, and make the first commit.

Git
git init && git [1] . && git [2] -m [3]
Drag options to blanks, or click blank then click option'
Aadd
Bcommit
C"Initial commit"
Dpush
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'push' instead of 'commit' for saving changes.
Forgetting to add files before committing.
Not quoting the commit message.

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