HiveBrain v1.2.0
Get Started
← Back to all entries
snippetjavascriptTip

Create a new Git repository

Submitted by: @import:30-seconds-of-code··
0
Viewed 0 times
repositorycreatenewgit

Problem

The first thing you need to do when starting a new project is to initialize a new Git repository. This sets up all the configuration files needed by Git to track changes in your project.
Simply running git init in the project directory will create a new repository. You can also specify a directory to create the repository in a different location, using git init <directory>.
> [!NOTE]
>
> You only need to run git init once per repository. Running git init in an existing repository is safe, so don't worry about accidentally breaking anything.

Solution

# Usage: git init [<directory>]

cd ~/my_project
git init
# Initializes a repo in ~/my_project

cd ~
git init my_project
# Initializes a repo in ~/my_project


> [!NOTE]
>
> You only need to run git init once per repository. Running git init in an existing repository is safe, so don't worry about accidentally breaking anything.

Code Snippets

# Usage: git init [<directory>]

cd ~/my_project
git init
# Initializes a repo in ~/my_project

cd ~
git init my_project
# Initializes a repo in ~/my_project

Context

From 30-seconds-of-code: create-repo

Revisions (0)

No revisions yet.