WalzoneInterview Prep
📞 Interviewing soon? Practice with a realistic AI mock phone interview — it calls you, then scores you. First 15 min FREE →

Git · Basic · question 4 of 100

How do you initialize a new Git repository?

📕 Buy this interview preparation book: 100 Git questions & answers — PDF + EPUB for $5

To initialize a new Git repository, you need to perform the following steps:

Open a terminal or command prompt window. Navigate to the directory where you want to create the new Git repository. Run the git init command.

Here’s an example of how to create a new Git repository:

Open a terminal window. Navigate to the directory where you want to create the new Git repository. For example, if you want to create a new repository in a directory called my-project, you would navigate to that directory using the cd command:

    cd my-project

Run the git init command to initialize a new Git repository:

    git init

After running this command, Git will create a new .git directory in your project directory. This directory contains all the files and metadata that Git uses to manage your project’s version control.

At this point, your new Git repository is ready to use. You can start adding files to the repository, making commits, and branching the codebase as needed.

Here’s an example of how to add a new file to the repository and make an initial commit:

Create a new file in your project directory. For example, create a file called README.md:

    echo "# My Project" > README.md

Use the git add command to stage the new file for commit:

    git add README.md

Use the git commit command to create a new commit with a message describing the changes you made:

    git commit -m "Initial commit"

After running this command, Git will create a new commit with the changes you made to the README.md file. The commit will be stored in the repository’s history, along with a message describing the changes you made.

That’s it! You’ve now initialized a new Git repository and made an initial commit with some changes to the codebase. You can continue adding files and making commits to the repository as needed.

Reading is step one. Saying it out loud is the interview. Our AI interviewer calls your phone and runs a realistic Git interview — then scores it.
📞 Practice Git — free 15 min
📕 Buy this interview preparation book: 100 Git questions & answers — PDF + EPUB for $5

All 100 Git questions · All topics