After installing Git on your machine, the first thing you'll need to do is set up a repository. A repository (repo) is a centrally located folder for storing all your code. Once you create a Git repository with your files and directories, you can start tracking changes and versions. In this section, you'll learn how to get a repository up and running.
Remote repositories and local repositories
There are two types of Git repositories: remote and local.
- A remote repository is hosted on a remote, or off-site, server that is shared among multiple team members.
- A local repository is hosted on a local machine for an individual user.
While you can take advantage of Git version control features with a local repository, collaboration features—like pulling and pushing code changes with teammates—will be better suited on a remote repository.
How to create a repository
There are two ways to create a local repository on your machine. You can create a new repository from scratch using a file folder on your computer or clone an existing repository.
You can create a new repo from scratch using the git init command. It can be used to introduce Git into an existing, unversioned project in order to start tracking changes.
Use the git clone command to copy a remote repository onto your local machine.
By default, git clone automatically sets up a local master branch that tracks the remote master branch it was cloned from.
A cloned repository has the same history log as the original one. You can refer and backtrack to any of those commits within your local repository.
Ready to set up a repo for yourself? Follow our step-by-step tutorial for creating a git repo.