+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Git and GitHub for Beginners - Crash Course - YouTube

Installing Git : Install Git | Atlassian Git Tutorial

Visual Studio : Download and Install : Visual Studio Code - Code Editing. Redefined

 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is Git ?

Git is what we call a version control system , It is an open source and free and the mostly used version control system in development today . Programmer interact with Git on a daily basis .

What is Version Control ?

Version control is basically a way were we programmers track our code changes .  We basically save our initial version of code into Git . And when we update code we can save it into Git Again and again and over time we can look into all the code changes we have made over time . This helps us to see what we did when , this helps us to track down bugs and as well as to go back to the previous version of the code if we need to . 

Git is the tool that tracks your changes in your code over time. GitHub is the website we you host all of your Git repository  - being online makes it easy to work with other people and organize your project into a portfolio to show potential employers . 

Git Command :

Clone : Bring a repository that is hosted somewhere like GitHub and yuolu want to bring into a folder on your local machine.

add : when you have updated files or have deleted files or folders, you might want tell Git that you have made some changes and want git to track those changes. 

Committing : Committing your changes places your changes to the local repository

Push : Once you have made changes locally on your computer and when you are ready to put them on Git. You upload your file to a place like GitHub or another what we call a remote repository . 

Pull : When there are changes on the GitHub and you want to bring them on to your local machine, you use the Pull command

Repository : on GitHub

A repository is basically a project 


Here we can create a New Repository 

We are going to create a new repository here and give it a name - demo-repo , 


And you can create files and folders for this repository locally for your machine or you can create it straight away on the Online editor in the GitHub  website, so I am going to go ahead create a basic mark down file called "readme" and this is the basic file you will find in every project that contains text to describe what the project is all about and what it does and any other relevant information .

So I am going to create a new file


or 


I am going to name it "readme.md"  md - for markdown 


I will put in some text there and come down to the bottom and click  "Commit new file" 

And If I do not write anything here which is the place holder of the file. This will take it as the default text.


And this is the commit message which is been taken and this is the read me file .

Now I clicked the "Edit" Button and updated the the file and now the default commit message is .


And by committing I saved my changes here, 

And now if I want to see all the history of my changes that I have made . I can come here 

I can click on the right hand side and click on History .


or 


I click on commits and you can see each commit has a unique commit id 


click on the file .

And you can come back on this one to see what was added. The Green background with + sign means these lines were added.


And we go back and click on the previous commit. 

You see a red block with a - sign which means this line was deleted. And the green with a plus sign means this line was added. Anything that's white means it stayed the same,

So this is a very basic view of seeing changes. Now what about using this on your local machine.

If you are using a Mac or  Linux system you should already have Git installed . You can check this 

Check if Git is installed.

$ git --version 

If Git is not installed, check out this tutorial below from Atlassian which 

Install Git | Atlassian Git Tutorial

When you are installing Git for window I do recommend to use the "Git Bash" option  from the install menu.


Can choose command prompt and it will set it in command prompt for you. But in the past I had an easy time with Git Bash on windows . 

There is one more piece of the setup before we get started with the Git tutorial and that is getting a Code editor. Of course you can write code in whatever you want any kind of word processing software will do, from nopad to microsoft word . But there are specific ones made for coding , many of them are really useful and free . 

Visual Code Editor : Is a free code editor made by Microsoft .


It is widely used by people learning to code and professionals alike. 

Visual Studio Code - Code Editing. Redefined

Now I have Visual Studios opened with no files or folders inside . 


Click the first one and this part comes out .


choose a folder named "Git" by the tutor and opened it was an empty folder . And now we have an folder where we can put all the files in .

But we are not going to write now. We are going to pull the repo that we created.

Open the terminal - Open View Menu . Now why it is git here in the terminal is only because my folder is named Git.


Click on the Clone or Download here .



hit Enter

And now you can see a folder here .


Now I will change the directory to demo-repo which has been cloned from the GitHub repo . 
And now it says Git-Master 


Now how do you know if you are actually in the Git Repository now -- By checking the Hidden folder.

The .git directory -- this indicates that you are in the Git repository. 

$ ls -la -- list all the files including the hidden ones. 

The .git folder saves all of your code changes and commits . It has all of the changes that is recorded in the history of this repository which includes the one we made on GitHub.com

I am going to open up the readme and add some more code to it. Now that I have saved this file . I have to save the change in Git . 

$ git status 

shows all of the file that were updated , created or deleted, havent been saved in a commit yet ,

for example if I come here and save a new file and call it index.html 


And put some contents inside the file. And now we rerun the command

$ git status

It says one is modified and one 1 file is untracked . meaning the git does not know about this file yet, You need to tell Git to track the file before you save it to Git. And to do that you need to add the Git add command 

$ git add .

 now check again

$ git status

Now you can see all of the changes are been tracked. And they are ready to be committed. 

Lets commit it now.

$ git commit -m "first commit"

- m is for message

You can add one more for the description box

$ git commit -m "first commit" -m "description"

Title and for description box


But we still only saved our code locally. It isn't live on GitHub yet . 

And to make it live on GitHub we will use another Git command

$ git push

Meaning to push the , in order to push to GitHub you need to prove to GitHub that you are the owner of your account . So you need to connect your local machine to the GitHub account somehow. 

And they way it is done is using SSH keys. You need to start by generating a SSH key locally by using 

$ ssh-keygen -t rsa -b 4096 -C "github-email-address"

- t --  You specify the type of encryption and then the type of encryption .


Now I am going to seach for the key that I have generated . And now that I find there are two .


testkey.pub is the key that you are going to upload to the github interface .Pub stands for public which is your public key . which means that is okay for other people to see this key . The key that was generated with out the .pub key is the private key . The public key is put on GitHub and you have this privat key to tell GitHub that you are the one who generated this Public Key . 

There is also a terminal command which is called pvcopy .



On GitHub I am going to go to my settings 


In the list of all settings , you are going to ssh and gpg keys


Add new SSH key ,


This is all for your reference , 


Click on Add SSH key . The key will be successfully added . 

And now you are just left to do is , Git command line interface knows about the keys that you have just generated , 

And we will add this , And I am going to link all of these things in the description below . 

Git Push .

$ git push origin master

master is the branch that we need to push to and we will get there in a minute . And I will create new folder here demo-repo2 , 


I will add a file in here in the new folder . 


And now if I want to convert this into a Git Repository I can , I can use the command line and say 

$ git init

And now if I say

$ git status 

I can see this is untracked , I will goahead and add that file in 

$ git add readme

$ git status 

now the file is read to be committed. 

$ git commit -m "created readme" -m "description here"

What if I want to push this to live.

$ git push origin master

This throws a fatal error. 


This is because we did not clone it from GitHub.

We created demo-repo2 locally . 


So git says I don't know where to push this to , because this is not connected to anything. So we have to create that connection . 

And the way to do that is to create an empty Git-Repository on GitHub .

> Create New Repository .


Now i have another empty repository . To start pushing here I am going to copy this. We are going to use

$ git remote -- remote means not on this repository which is not on this computer.

$ git remote add origin <URL>


And I can check that my using the below command. 

$ git remote -v

Now you can pust it .

$ git push origin master 

now there is a short cut if you do not want to use the work "origin master"

-u upstream in future you can mention as saying an upstream telling Git this is where I want to push it by default .

$ git push -u origin master 

And in the future you can pust it to the master without using the key work "origin master" . 

GitHub Workflow

we do not have the > git add step in GitHub , for  GitHub takes care of that . 


So really,  by committing in git hub we are adding and committing at the same time on GitHub . And that's all really because this was our repository and we had full access to what we wanted. We could just update the code by committing in the GitHub interface. 

And if we didn't own the repository or if we didn't have the access rights . or we needed other people to review our code. Before we merged it with all the rest of the code , then we also have to take the extra step of making a PULL REQUEST. Which is something that we are going to cover later in this video. 


And then again if we didn't have access rights or have to do a code review , we will need to make a pull request . 

Git Branching :

Lets go over some of the concept of Branching and then we shall dive into practice example . Now what is Git Branching ? 

We have seeing in our example that we are in our Master Branch . 


Master : Is the naming convention for the main or the default Branch in a Repository. And if you are working on Just one Branch , that's where the code will live. And all your commits and all your code will be in that one Branch . So this is called Branching . It is more like a tree which has multiple Branches. So we saw that we have a Master Branch and we were committing to that Master Branch . 

But we can also make another branch . We we call it feature Branch . 





















 


































Comments

Popular posts from this blog

GitHub : Troubleshooting

Git Commands : Tags

GIT - Company