How to Create and Clone a Repository in Git
When you’re starting a new coding project the first thing to do is create the project’s Git repository.
This short tutorial will guide to create a brand new Git repository & clone an existing repository :-
1. Create a directory for a repository in your home directory:
mkdir new-project
2. Now we’ve got to get the new repository initialized.
Get into the new directory:
cd new-project
Then, initialize it with this command:
git init
We can verify a repository was initialized with this:
ls -al
We should see a .git
directory in the listing.
3. Create a Repository README File & add your code
echo "Code for my new project" >> README.md
4. Add and Commit the README File to the Repository
Now, after adding the code to the file, we need to add it to the staging area and commit it to the repository. We can do this with these commands:
git add README.md
git commit -m "Added README.md to the project"
How to Clone an Existing Repository
If you want to join an existing project that has already been started by someone else, you have to clone
it.
Cloning a repository from a remote server means downloading it to your computer so you can work on the project.
Here is a guide to clone repository from git :
1. Move to the location where you want to download the project
$ cd new-projects
2. Download the project by cloning it
$ git clone https://github.com/gittower/git-exisiting-project.git
Leave a Reply