How To Clone A Git Repository

How to Clone A Git Repository

This article will explain how to clone a git repository from a server to your local machine’s hard drive. This is the usual way you will download code to your machine for development. 

$ cd /to/the/folder/you/want/to/save/code/in

Clone Repository From A Server

Use git clone to download the files from an online repository.

$ git clone https://github.com/the/url/the_file.git

Rename Folder

Rename the folder you just downloaded to the name of a new repo that you create on your personal public (or private) github account. 

Push To GitHub

Navigate to the new folder on your computer that you just downloaded from GitHub. 

Check the Orgin

Since we just downloaded these files from github. If we try to push them back to github, they will be pushed back to the origin. You can check the origin by using git remote -v

$ git remote -v

Outputs fetch and push as the GitHub URL you downloaded from. 

Push To GitHub

Use git remote set-url origin to set where you want to push the folder. For example, a repository that you set up on your personal GitHub account. 

$ git remote set-url origin https://github.com/your/github/repository/git-file.git

Check Origin is Correct

Use git remote -v to check if origin is set to your personal GitHub account. 

$ git remote -v

Now Push To Your GitHub Account

This command will actually push the files you downloaded earlier to your GitHub account. 

$ git push origin master

1 thought on “How To Clone A Git Repository”

Leave a Comment

Your email address will not be published. Required fields are marked *