Create or clone a repository #
From a remote server #
The most common way to create a repository is to create the remote copy first, using the web interface of your host (Github, Gitlab, Bitbucket, etc.).
You will be asked to give the repository a name. Then you will be provided an address that allows use to clone the repository on your own machine (via ssh or https).
To do so, navigate on your machine to the folder where you want to clone the repository, and run
git clone <address>
Note. After cloning a repository, you can verify that it contains a (hidden) subfolder called
.git
. Recall that this is what distinguishes a git repository from a regular folder.
Note. You can safely move a cloned repository to another location on your machine (as long as it contains the
.git
subfolder).
With the same command, you can clone any public repository that you find online (e.g. hosted on GitHub).
To clone a specific branch, run
git clone -b <branchName> <address>
Locally #
Alternatively, you can create a git repository on your machine with the git init command. This may be convenient if you want to create a git repository from an existing (nonempty) folder.
If you create a git repository locally, then you will need to declare your remote(s) manually (with git remote).