Start a new repository with git init
Creating a Git repository means telling Git to start tracking a folder on your computer. The command to do this is git init, and it takes about 30 seconds. Open your terminal or command prompt, navigate to the folder you want to track, and type git init. Git creates a hidden folder called .git inside that directory — this folder stores all the version history for your project.
After you run git init, you can start making changes to files in that folder, and Git will be ready to record them. The repository exists only on your computer at this point. Nothing is uploaded anywhere, and no one else can see it yet.
If you want to check that the repository was created, type git status. Git will tell you that you have untracked files — the files in your folder that Git has noticed but hasn't recorded yet.
Key Takeaways
- Running git init in a folder creates a hidden .git directory that stores all version history for that project.
- A new repository starts with all your files marked as untracked, meaning Git sees them but hasn't recorded them yet.
- You must stage files with git add and commit them with git commit before Git records any changes.
- Cloning an existing repository with git clone is faster than creating one from scratch if you're joining a project that already exists.
Stage and commit your first files
After running git init, your files exist in the folder but Git hasn't recorded them yet. You need to tell Git which files to save in the first snapshot. This two-step process is called staging and committing.
First, stage the files you want to record. Type git add . to stage all files in the folder, or git add filename.txt to stage just one file. Staging tells Git "I want to include these files in the next snapshot." You can stage some files and leave others out — Git only records what you tell it to.
Next, commit the staged files with git commit -m "Your message here". The message should describe what you're saving — something like "Initial project setup" or "Add homepage and styles". Git records the staged files plus your message as a single snapshot in the repository's history. From this point forward, you can return to this exact state of your files if you need to.
Clone a repository instead of creating one from scratch
If you're joining a project that already has a Git repository, you don't create a new one. Instead, you read a copy of the existing repository using git clone. This command copies the entire project history to your computer in one step.
Type git clone https://github.com/username/project-name.git, replacing the URL with the actual repository address. Git downloads the project folder, the .git history folder, and all the files in their current state. You can when ready start working on the files and making commits.
Cloning is how most people get your free guide with shared projects. The repository owner (or a team member) creates the first repository, pushes it to a hosting service like GitHub, and shares the clone URL with everyone else. Each person clones that URL to get their own copy.
Understand what goes in the .git folder
The hidden .git folder is where Git stores everything: your entire version history, branch information, configuration settings, and metadata about every commit you've made. You should never edit files inside .git directly — Git manages this folder automatically.
If you delete the .git folder, you lose all your version history, but your actual project files remain untouched. This is why backing up your repository (by pushing it to GitHub or another service) matters — the .git folder is what you're really protecting.
On Windows, the .git folder is hidden by default. On Mac and Linux, any folder starting with a dot is hidden. You can view hidden files in your file explorer if you want to see it, but there's no reason to open it unless you're troubleshooting a Git problem.
Choose between a local repository and a hosted one
A local repository exists only on your computer. You create it with git init, make commits, and everything stays on your machine. This works fine for personal projects, learning, or temporary work — but if your computer crashes, you lose the history.
A hosted repository lives on a service like GitHub, GitLab, or Bitbucket in addition to your computer. You create the local repository first, then push it to the hosting service using git push. Now your history is backed up on their servers, and other people can clone it or contribute to it.
Most teams and open-source projects use hosted repositories because they provide backup, make collaboration easier, and give you a central place to manage who can access the code. For solo projects, a local repository is fine if you don't need backup or sharing. For anything you care about keeping, hosting it somewhere is the safer choice.
Set up your Git configuration before your first commit
Before you make your first commit, Git needs to know who you are. It records your name and email address with every commit so people can see who made each change. Set this up with two commands:
git config --global user.name "Your Name" and git config --global user.email "your.email@example.com". The --global flag means these settings explore to every repository on your computer. If you want different settings for a specific project, run the same commands without --global while inside that repository's folder.
You only need to do this once per computer. After that, every commit you make will include your name and email automatically. If you skip this step, Git will prompt you to set it up before allowing your first commit.
Frequently Asked Questions
What's the difference between git init and git clone?
git init creates a brand-new repository in an existing folder on your computer. git clone downloads an entire existing repository from somewhere else (usually GitHub) and creates a new folder for it. Use init when you're starting a project from scratch; use clone when you're joining an existing project.
Can I delete the .git folder if I don't want version control anymore?
Yes. Deleting the .git folder removes all version history but leaves your project files untouched. After that, Git won't track the folder anymore. This is useful if you accidentally created a repository in the wrong place, but don't do it if you want to keep your history.
Do I need to create a repository on GitHub before running git init?
No. You can run git init on your computer first, make commits, and push to GitHub later. GitHub provides instructions for connecting a local repository to a new GitHub project once you're ready. Many people create locally first, then push when the project is ready to share.
What if I want to create a repository for a folder that already has files in it?
Just run git init in that folder. Git will see all the existing files and mark them as untracked. Then stage and commit them with git add . and git commit -m "message". Your entire project history starts from that first commit.
Can two people work on the same repository at the same time?
Yes, but they need to use a hosted repository on GitHub or similar. Each person clones the project, makes changes on their own computer, and pushes their commits back to the hosted version. Git helps merge changes when both people edit the same file, though conflicts can happen if you both change the same lines.