Git - Create First Repository and Clone on local computer using git-bash Cli

GitHub -
Github is a most popular cloud-based open source repository system, It allows the team to act and submit their work at a central location. 


Developer and store and manage their code, as well as track and control changes to their code. mainly used for source code management in software development. It is a Command Line Interface(CLI) tool and can be mastered easily. 


Prerequisites -

  • One Github account - You can set up your free account (if don't have).
  • One Windows Machine with installed Git software.
Step 1- Download and install Git Software -
You can download the latest version of Git from its official's site - https://git-scm.com/downloads
Once finish the download, You can start the installation by double click on file - Git-2.18.0-64-bit.exe. It's very easy installation just follow the steps.

Step 2- Create First Repository on GitHub:
Let's follow the steps below to create your first Github repository -
  • Log on to your GitHub account - https://github.com/login
  • Create your first Repo on the login page click on New Repository
  • On the next screen enter your repository name (myfirstrepo) > check on Public > click Initialize this repository with Readme  > Click on Create Repository.
Your Repository has created and initialized. Your next screen should be like this.


Step 3- Setup SSH key 
In this case, we already initialized our repository while we set up it on GitHub account so no need to initialized here. 
Now, Open Git Bash on your local computer and follow the steps below-
  • On the Git Bash command type command below and hit the enter button to generate SSH key.
$ ssh-keygen -t rsa -C "asingh@domain.com"
You will get output like in below image.
  • Now open /C/Users/amar/.ssh/id_rsa.pub file in your favourite editor and copy the SSH key. You can find your file path in the current user's home directory inside folder .ssh.

$ vi /c/Users/amar/.ssh/id_rsa.pub

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDyph6mttPuEnUOWJFTuRmFNp7WS4xe1x4WPTzlanMf5PnTv1TQxWbchaITQQMGCqF+3/6/r8JTip5yuC0vaku+0CmFPCVfk3w8dmqew3n8b3/ki98ieei8OnPuALDC7+lrcknstl+MnF3WDsyi0ZEfvABaj6m3BUIGfwawG18+wcvgpaYYoPnKEXvYLY1D05ZlBW/9EQuHLHNimXGiwRqLFBI5qYSBC9pRXLA6X10gbaFORKuYJSQkpP4dKj7F8aD1tIASW55DtDtVrEWf2avyRh5Hca6Y0cO3+HvKnCSie3sUyZ+8A9gJmQ7sv629uIGNmpZrJGE9hfrv72zKgkH6f asingh@gmail.com
  • Copy above ssh key and paste into your GitHub account.
  • Go into Git Hub account settings -
  • Now, click on SSH and GPG key button on left side > NewSSH key as in below picture.

  • Now copy your SSH key in the box. Copy SSH key from local system path -/C/Users/amar/.ssh/id_rsa.pub
Once you paste the SSH key click on Add SSH key button.

Step 4- Clone repository to your local system.
After successfully added SSH key, Your Git Bash is ready to clone your first Repository.
  • Log on to your GitHub account and copy Repository URL as in the picture below - Change clone type to SSH before you copy the URL


  • Once you copy the repository URL type below command at your Git Bash shell.
$ git clone git@github.com:amars1986/myfirstrepo.git
  • Now go to your cloning path 
$ cd myfirstrepo/
  • Check the Repository status using the git status command.
$ git status

On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean

Your Git repository master branch is up-to-date. 

Your first cloning completed successfully, In my next blog we will learn how to create, add, commit and push newly added file and folder to out Git repository