hand-businesswoman-touching-hand-artificial-intelligence-meaning-technology-connection-go-

GitHub101

Git is a version control system that lets you manage and keep track of your source code history. GitHub is a cloud-based hosting service that lets you manage Git repositories. If you have open-source projects that use Git, then GitHub is designed to help you better manage them.


Git is software that runs locally. Your files and their history are stored on your computer. You can also use online hosts (such as GitHub or Bitbucket) to store a copy of the files and their revision history. Having a centrally located place where you can upload your changes and download changes from others, enable you to collaborate more easily with other developers. Git can automatically merge the changes, so two people can even work on different parts of the same file and later merge those changes without loosing each other’s work!


Creating a repository

Prerequisites

Download Git on your windows device from https://git-scm.com/downloads and install the software.


Step 1. Create a Repository

Go to https://github.com/ and sigup.

  1. In the upper-right corner of any page, use the drop-down menu, and select New repository.

  2. Type a short, memorable name for your repository. ...

  3. Optionally, add a description of your repository. ...

  4. Choose a repository visibility. ...

  5. Select Initialize this repository with a README.

  6. Click Create repository.

This is what it will look like. I named my first repository as #learningGitHub


Step 2. If we are setting up the git for the first time, we can configure the git with name & email.


Now open Git Bash and locate your directory where the code is present.


git config --global user.name "Your_Name" && git config --global user.email "Your-Email"

Step 3. Initialize Git Repository

git init

Note:- On your Project’s root directory

It initializes the git repository in local project & will make .git folder that contain important folders and files.


Step 4. Commiting files into the git repo.


There are three steps :-


Step 1 : We need to add a file to staging area .


git add <File_Name> {{For Single File}}
git add . {{For all the files in current Directory}}

Note :- In place of <File_Name> add your file and if you want select all the files in current directory then use {{ . }} or {{ * }}


To check,if files are added or not,use this:

git status

Step 2 : Commit a file into the git repo is to write a commit message.

git commit -m "First Commit"

Note :- In the “Double Quotes”, you should write your message.


Step 3 : Push the file into a remote repository. {{Github}}


To add files in your remote repo use this :

git remote add origin git@github.com:"Username_on_github"/"Repository_Name"

Note :- This above command is a single command & Now place your git-hub username (without any quotes) and put your repository name (without any quotes).


Like this :

git remote add origin git@github.com:XYZ/project.git

And if you don’t understand this then go to your repository on git-hub and click on clone or download button and copy url with SSH method.


To check :

git remote -v

Step 5. Create SSH Key.


Why we use SSH?


In HTTPS method, you will need to fill our username and password at every visit, which will be very inconvenient.

By using the ssh protocol, we can connect and authenticate to remote servers and services. With ssh keys we can connect to GitHub without supplying our username and password at each visit with the help of passphrase.


1. Generating New ssh key and adding it to a ssh agent.

ssh-keygen -t rsa -b 4096 -C "email"

Note :- Place your email in “double quotes”.

This creates a new ssh key using the provided email as a label.

1.1. For default file Press {{ ENTER }}

/home/{{username_of_pc}}/.ssh/id_rsa: ENTER

1.2. Enter a passphrase.

1.3. Now our identification has been saved in

Private Key : /home/{{username_of_pc}}/.ssh/id_rsa & Public Key : .ssh/id_rsa.pub

2. Adding our ssh key to the ssh agent

eval "$(ssh-agent -s)" it gives like {{agent_id : 15800}}

3. Now we add SSH Private key to ssh-agent to our default path.


ssh-add ~/.ssh/id_rsa

4. Adding a new ssh key to your github account.

Go to github.com >> Under Profile Photo (Drop Down) >> Settings >> Use SideBar {{ SSH & GPG Keys }} >> Then go to this directory on your computer {{Home/.ssh/id_rsa.pub}}

Open this file and copy your key.


Create new SSH key >> Title the filed with descriptive label >> Paste key into a “Key Field” >> Click on {{ Add SSH Key }}


5. Now for Testing SSH Connection.

ssh -T git@github.com

After running this , it will show this messege on Git Bash!!

Hi {{ USERNAME }}! You've successfully authenticated but github does not provide shell access.


6. Final PUSH

git pull --rebase origin master git push origin master

Note : Change ‘master’ whatever branch to push.


Then you can successfully push your file to remote server and you can setup a SSH Connection.

To check the connection

git log


#github #git #repository #git101



42 views0 comments

Recent Posts

See All