Create Repository

A Git repository is the foundation of modern software development. It stores your project files alongside the history, branches, and configuration Git needs to track changes. A local repository lives on your computer, while a remote repository is hosted on a service such as GitHub or GitLab. Creating both correctly gives you a reliable place to build, back up, and collaborate on your project.
A local repository is usually a project directory containing a hidden .git folder. That folder holds Git’s internal metadata and should not be edited manually.

A remote repository serves as a shared copy of the project. It provides:

  • A backup outside your local machine
  • A central location for team collaboration
  • Access from multiple computers and devices
  • Support for pull requests, issue tracking, and reviews

You can work entirely with a local repository, but creating a remote one is especially useful when a project needs to be shared or published.

Creating a Local Repository

Start by opening Terminal on macOS or Linux, Command Prompt on Windows, or PowerShell. Move into the project directory with the cd command:

cd /path/to/your/project

If the project does not exist yet, create the directory first:

mkdir my-awesome-project
cd my-awesome-project

Initialize Git in that directory:

git init

Git will display a message similar to the following:

Initialized empty Git repository in /path/to/your/project/.git/

The repository is now ready, but the initial files still need to be added and committed. For example:

git add .
git commit -m "Initial commit"

The git add command stages files for the next commit, while git commit records them in the repository’s history.

Before making commits, make sure Git knows who you are:

git config --global user.name "Your Name"
git config --global user.email "you@example.com"

These settings are attached to each commit and help collaborators understand who introduced a change.

Creating a Remote Repository on GitHub

To create a remote repository, sign in to GitHub and follow these steps:

  1. Open the + menu in the upper-right corner.
  2. Select New repository.
  3. Enter a clear repository name, such as my-awesome-project.
  4. Add an optional description explaining the project’s purpose.
  5. Choose whether the repository should be Public or Private.
  6. Decide whether GitHub should initialize the repository with a README, .gitignore, or a license.
  7. Select Create repository.

A public repository is visible to everyone and may be cloned by other developers. A private repository is restricted to authorized users and is commonly used for proprietary or confidential work.

If you initialize the remote repository with a README, .gitignore, or license, GitHub creates those files immediately. Otherwise, the remote repository begins empty.

Cloning an Existing Remote Repository

If the remote repository already exists, clone it instead of running git init:

git clone https://github.com/your-username/my-awesome-project.git

The command downloads the project and creates a local repository in a directory named after the remote repository. Git also configures the remote automatically under the name origin.

You can verify the connection with:

git remote -v

If you prefer SSH, use the repository’s SSH address instead:

git clone git@github.com:your-username/my-awesome-project.git

SSH is convenient for frequent use because it avoids entering a personal access token for every operation, provided your SSH keys are configured correctly.

Publishing an Existing Local Repository

Suppose you already created a local repository with git init and now want to publish it to GitHub.

First, create an empty remote repository on GitHub. Do not initialize it with a README if you intend to push the existing local history, because the two repositories will not yet share a common commit.

Next, copy the repository’s HTTPS or SSH URL and add it as a remote:

git remote add origin https://github.com/your-username/my-awesome-project.git

Rename the current branch to main:

git branch -M main

Then push the local commits and establish the upstream relationship:

git push -u origin main

The -u option links the local main branch to remote/main. After this setup, later updates can be pushed with a shorter command:

git push

If git remote add origin reports that origin already exists, inspect the current configuration with:

git remote -v

You can update the remote URL when necessary:

git remote set-url origin https://github.com/your-username/my-awesome-project.git

Choosing the Right Project Setup

The simplest approach depends on where the project begins:

  • Starting locally: Run git init, make your first commit, create an empty remote repository, and push.
  • Starting on GitHub: Create the remote repository, clone it locally, and make changes in the cloned directory.

These workflows keep the commit history consistent and avoid unnecessary merge conflicts when the repositories are first connected.

Essential Practices for New Repositories

Add a Useful .gitignore

A .gitignore file tells Git which files should not be tracked. Generated files, dependency directories, logs, and local configuration files often belong there.

Common examples include:

node_modules/
dist/
.env
*.log

Ignoring .env files is particularly important because they may contain passwords, API keys, or other sensitive information. Be careful not to commit secrets and then rely only on deleting them later, since Git history may preserve them.

Write a Clear README

A README.md file explains what the project does, how to install it, and how to use it. A helpful README often includes:

  • The project’s purpose
  • Installation instructions
  • Basic usage examples
  • Configuration requirements
  • Links to documentation or support channels

Select an Appropriate License

If you intend others to use, modify, or distribute your code, add a license. MIT is simple and permissive, while Apache 2.0 includes explicit patent licensing terms. Other options include the BSD, GPL, and Mozilla Public License.

Without a license, others generally do not have permission to reuse or redistribute the code, even when the repository is public.

Use Consistent Naming

Choose a descriptive repository name with lowercase letters, hyphens, or underscores. For example:

customer-api
design-system
portfolio-website

Avoid spaces, temporary names, and abbreviations that may be unclear to new contributors.

Review Before Committing

Use the following commands to inspect your changes:

git status
git diff

git status shows which files are staged, modified, or untracked, while git diff displays unstaged changes. Reviewing your work before committing helps prevent temporary files or sensitive data from entering the project history.

Once the local and remote repositories are connected, you can continue with normal development: commit changes regularly, push them to the remote, and use branches for features or bug fixes. A well-created repository provides a clean foundation for effective version control and collaboration.