Creating a new repository
Start your free 7-days trial now!
To create a new repository run the git init
command in the directory which contains the files that you would like to track.
A git repository is a directory having a .git
directory serving as a virtual storage of your project. This enables you to track versions of your code and come back to them when needed.
From scratch
To create a new repository in the project2021
directory:
cd ~/project2021/git init
Running the above command will create a new .git
subdirectory under project2021
(current working directory).
To create a new directory called project2022
in the current directory and create a new project:
git init project2022
The above is equivalent to running mkdir project2022 && cd project2022 && git init
It is not good practice to create a new repository inside another (i.e. nesting repositories) unless absolutely necessary, as you then need specify which .git
folder to store changes in each time you make an update. As you can imagine, this quickly becomes very complicated to maintain.
Cloning an existing repository
To clone an existing repository we can use the git clone command with the following syntax:
Local repository
git clone <filepath> <newprojectname>
where:
<filepath>
stands for the filepath of the local repository you would like to clone.<newprojectname>
stands for the name to give the cloned project in your home directory
Remote repository
git clone <URL> <newprojectname>
where:
<URL>
stands for the URL of the repository you would like to clone<newprojectname>
stands for the name to give the cloned project in your home directory