Creating a Git repository means turning a folder into a version-controlled project

A Git repository is a folder that Git watches and records. Every time you save changes to files inside it, Git can store a snapshot of what changed and why. To create one, you run a single command in the folder you want to track, and Git sets up the hidden files it needs to do its job. That takes about ten seconds.

The two most common starting points are: you have an existing folder with files you want to start tracking, or you are beginning a new project from scratch. Both use nearly the same process, with one small difference at the beginning.

Key Takeaways

  • Run git init inside any folder to turn it into a repository that Git can track.
  • Git creates a hidden .git folder that stores all version history; deleting it removes all tracking but leaves your files intact.
  • After initializing, you stage files with git add, then save them with git commit and a message explaining what changed.
  • You can create a repository on your computer first and connect it to GitHub later, or clone an existing repository from GitHub to start with code already there.

Initialize a repository in an existing folder

Open a terminal or command prompt and navigate to the folder you want to track. On Mac or Linux, use cd followed by the folder path. On Windows with PowerShell or Command Prompt, do the same. Once you are inside the folder, type git init and press Enter.

Git creates a hidden folder called .git inside your project. This folder holds all the information Git needs: the history of every change, branches, configuration settings, and metadata. You will not need to open it or edit it by hand. On Mac or Linux, hidden files start with a dot; on Windows, you may need to turn on "Show hidden files" in your folder settings to see it.

Your files remain exactly as they were. Git is now watching the folder, but it has not yet recorded anything. The next step is to tell Git which files to track and save a first snapshot.

Add files and make your first commit

After running git init, type git add . (with a period at the end). This tells Git to stage all files in the folder for tracking. The period means "everything in this folder." If you want to stage only specific files, use git add filename.txt instead, replacing filename.txt with the actual name.

Next, type git commit -m "Initial commit" and press Enter. The -m flag lets you add a message right in the command. This message should describe what you are saving — "Initial commit" is a standard first message, but you can write anything that makes sense to you, like "Add project files" or "First version of calculator app."

Git now has a saved snapshot of your project at this moment. If you change a file later, Git can show you exactly what changed compared to this snapshot. You can make as many commits as you want, each one a new checkpoint you can return to.

Clone an existing repository instead of creating one

If someone else has already created a repository on GitHub or another hosting service, you do not need to run git init. Instead, use git clone followed by the repository URL. For example: git clone https://github.com/username/project-name.git.

Git downloads the entire project folder, including all history and branches, to your computer. You get a folder with the same name as the repository, ready to work with immediately. This is faster than creating a new repository and adding files one by one, especially for larger projects or when you are joining work someone else started.

Connect your local repository to GitHub or another hosting service

If you created a repository on your computer with git init and now want to push it to GitHub, you first create an empty repository on GitHub's website (without a README or license file). GitHub then shows you a set of commands to run in your terminal.

The commands typically look like this: git remote add origin https://github.com/username/project-name.git followed by git branch -M main and git push -u origin main. The first command tells your local repository where the remote copy lives. The second renames your branch to main (GitHub's default). The third uploads your commits to GitHub.

After this, every time you commit locally, you can type git push to send those changes to GitHub. Other people can then clone your repository or pull your latest changes.

Understand what Git tracks and what it ignores

Git tracks text-based files well: code, configuration files, documentation, and plain text. It can track binary files like images or PDFs, but it stores the entire file each time you commit, which uses disk space quickly. Large files or frequently-changing binaries (like compiled programs or video) are usually better stored elsewhere.

You can tell Git to ignore certain files by creating a .gitignore file in your repository folder. Inside it, list filenames or patterns — one per line — that Git should skip. For example, node_modules/ tells Git to ignore the node_modules folder that Node.js projects create. *.log ignores all files ending in .log. This keeps your repository clean and prevents accidental commits of temporary files, passwords, or system-generated folders.

Check the status of your repository

At any time, type git status to see which files have changed since your last commit, which files are staged for the next commit, and which files Git is ignoring. This command is safe — it only shows information and makes no changes.

git log shows your commit history: every snapshot you have saved, who made it, when, and the message you wrote. Type q to exit the log view. These two commands are your main way to understand what your repository contains and what has happened to it over time.

Frequently Asked Questions

What happens if I delete the .git folder?

Your project files remain untouched, but Git loses all history and stops tracking changes. The folder becomes a regular folder again. You can recreate the repository by running git init again, but you will start fresh with no previous commits. Do not delete .git unless you are certain you want to erase all version history.

Can I create a repository inside another repository?

Technically yes, but it usually causes confusion. Git will track the outer repository, and the inner one becomes just a folder with a .git subfolder inside it. Most workflows keep repositories separate. If you need nested projects, use Git submodules instead, which is a more advanced feature.

Do I need to be online to create a repository?

Yes for cloning an existing repository from GitHub or another service. No for git init — creating a repository on your computer works completely offline. You only need internet when you want to push changes to a remote service like GitHub or pull updates from one.

What is the difference between git init and git clone?

git init creates a brand-new empty repository in a folder you already have. git clone downloads an existing repository from a remote location. Use init when starting a project from scratch; use clone when you want to work with code someone else created or when you are joining an existing project.

Can I rename my repository after creating it?

The folder name can be changed anytime without affecting Git — just rename the folder normally. If your repository is on GitHub, you can rename it there too in the repository settings. Your local copy will not automatically know about the rename, so you will need to update the remote URL with git remote set-url origin followed by the new URL.