Git Tutorial - Part 1( Basics of Git )

In this tutorial, we will learn how to install git on windows and how to link one repository with GitHub . For other operating Systems, installation process will be different but commands will be same.We are using GitHub , but same commands can be used for any other Hosting sites.

Step 1:

Download and install windows installer.

During installation, make sure to mark “Use Git from the Windows command Prompt” option.

Step 2:

Create one account at https://github.com/

Step 3:

Create one Repository on Github clicking on “New Repository” button.By default , your repository will be ”public”. You can also create private repositories, those are visible only for you and members added by you.

Step 4:

Click on “Create repository” and next your repository will be created on GitHub.Open “Git Bash” from “start” _and type** **“ls -al ~/.ssh”_ and hit enter.

If you have already public and private key pairs, you will see file pair like “id_rsa.pub and id_rsa” .i.e. same file names but one with ”.pub” extension. Then you can skip Step 5, which explains how to create a private-public key pairs if not exists.

Step 5:

Create key pairs:

on ”Git Bash” window, enter

$ cd ~/.ssh
$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

(it will ask to enter file in which to save the key, don’t write anything, just press enter),enter one password, repeat it and hit enter. next one key pair will be generated.You can check them by using _“ls” _command.

Step 6:

Suppose generated keypairs are ”id_rsa” and ”id_rsa.pub

type “clip < ~/.ssh/id_rsa.pub” and hit enter, it will copy your rsa key values .

Step 7:

Next open GitHub, click on your profile* icon -> settings -> SSH keys -> add SSH key* -> give one title , paste your content inside ”key” field and hit “Add key” button.

Setup on Local Machine :

Now we need to setup on our PC.

Step 1:

Click on “start” , type “cmd” and open terminal .

Type “git” and hit enter : some messages should appear as below if git was installed properly :

“These are common Git commands used in various situations:…etc”

Step 2:

Move to Desktop, create one new folder and move to it :

$ cd Desktop
$ mkdir gitTest
$ cd gitTest

Type “git init” and hit enter.

“git init” is used to start using git on any project that is not under git.

Step 3:

Set your username and email, on terminal :

$ git config --global user.name "your name"
$ git config --global user.email "your email"

Step 4:

Move to your GitHub webpage and copy the SSH link of the repository you have created above

Next on your terminal, type ” git remote add origin git@github.com:codevscolor/testReposito ry.git ” and hit enter (replace .git link with your copied link).Now your local folder is linked with this repository.

Step 5:

Create one “readme.txt” file on your repository :

on GitBash terminal, move to your Desktop’s gitTest folder and type

$ touch readme.txt  (It will create one readme file)
$ git add readme.txt"
$ git commit -m "Adding readme file" (one changes is committed locally. Now you should push this change to your git repository.)
$ git push origin master (it will push these changes to git)

(You may be asked to confirm your connection. type “yes” and enter your password )

You can check on your GitHub account , one readme file is added to your repository. :)

**So in a nutShell :

//Key pair Generation Process :
$ ls -al ~/.ssh

//if key is not available :
$ cd ~/.ssh
$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

//copy key :
$ clip < ~/.ssh/id_rsa.pub

//add it on GitHub SSH key settings
//Move to your folder on local PC

//Configuration :
$ git init
$ git config --global user.name "your name"
$ git config --global user.email "your email"
$ git remote add origin git@github.com:codevscolor/testRepository.git
$ git add readme.txt
$ git commit -m "Adding readme"
$ git push origin master