How to Initialize a New Git Repository in a Local Directory: Step-by-Step Guide

Ever needed to start a project from scratch, but weren't sure how to get Git tracking your changes?

In this guide, let’s see exactly how to initialize a Git repository in a local directory, step by step, to get you coding with version control in no time.

How to Initialize a New Git Repository in a Local Directory

Steps to follow:

1. Create a new directory for your project and navigate into it by running the following commands.

In this example, we’ll name the folder 'test':

- To create the folder, run the command: 'mkdir test'.

- To navigate into it, run the command: 'cd test'.

2. Type 'git init' and hit Enter to initialize the repository.

3. An empty Git repository is initialized.

4. Click on 'New File' icon to create a file.

5. Create or write some code or content.

6. Run the command 'git add .' to add all the changes to the repository.

7. Commit your changes with a clear, meaningful message by running the command: 'git commit -m "your commit message"'.

8. The files have been successfully added to the repository.

Congratulations!

You are now equipped to initialize a Git repository in a local folder and commit your changes.

Conclusion

Now, you’re all set with your Git repository initialized and ready to go.

With just a few commands, you've got version control set up, so you can track your changes confidently from the start.

Still have questions?

Send an email to archana@leadwalnut.com, OR

Book a FREE consultation with an expert developer here.