Downloading repository into locally initialized git

You can use “git clone” to directly retrieve a remote repository. Alternatively, you can use “git init” to create a git blank configuration in your system and start adding a remote repository. We will see the same in this article.

Create an empty directory.

~$ mkdir repotwo

Issue command “git init” to create a git environment locally in this directory.

~$ cd repotwo/

~/repotwo$ git init
Initialized empty Git repository in /home/paperspace/repotwo/.git/

~/repotwo$ ls .git/
branches  config  description  HEAD  hooks  info  objects  refs

Check and set username and email using “git config” and test the settings.

~/repotwo$ git config --list
user.email=Code Version Master
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true

~/repotwo$ git config user.name "Code Version Master"

~/repotwo$ git config user.email "codeversionmaster@codeversionmaster
~/repotwo$ git config --list
user.email=Code Version Master
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
user.name=Code Version Master
user.email=codeversionmaster@gmail.com

Add a known remote repository using “git remote add”.

~/repotwo$ git remote add origin git@github.com:codeversionmaster/repotwo.git

Check the list of remote repositories using “git remote -vv”.

~/repotwo$ git remote -vv
origin  git@github.com:codeversionmaster/repotwo.git (fetch)
origin  git@github.com:codeversionmaster/repotwo.git (push)

Now, you can use other git commands such as “git fetch”, “git checkout”, and other commands to retrieve the branches from the remote repository.