Git and GitHub - Using Git the right way to maximize your work

Today's lesson we will learn the basics of Git and Github

Git and GitHub - Using Git the right way to maximize your work Picture 1Git and GitHub - Using Git the right way to maximize your work Picture 1

Git and Github are two very familiar concepts to developers, in fact many people use them every day. So what do you need to know specifically about Git and GitHub? How to use them correctly from the beginning to work effectively later?

Git and Github Basics

Let's consider a story about two programmers working on a project together:

There are two programmers who are working together to build a software for a client. And these two guys choose to work together by each writing a little code and sending it to each other via email or some other common data transfer method. After receiving each other's code, each person will review and edit it, then work together to assemble the software they need to do. However, one day, Mr. A accidentally wrote the wrong code into the software, leading to a faulty product that neither of them had backed up before because the software was too large. And so the two guys worked together to rebuild the faulty feature and continued to send it to each other like that.

From the above story we see two problems arising here:

1. Each person codes their own code and sends it to each other via email, which is very time-consuming. Furthermore, Mr. B will not be able to know what Mr. A has changed, whether it affects the general code of the entire system or not, and merging code is very difficult to control.

2. Modifying code without a previous backup makes them have to rewrite the code from scratch when the software fails. The appearance of Git will help solve the problem of the two guys above quickly, in addition, Git has many other useful features. 

So what is Git and what is it used for?

Git is the name of a Distributed Version Control System ( DVCS ), one of the most popular distributed version control systems today.

DVCS means that each computer can store many different versions of a source code cloned from a source code repository, each change to the source code on the computer can be committed and then uploaded to the server where the main repository is located. And another computer (if they have access) can also clone the source code from the repository or clone a set of the latest changes on the other computer.

In Git, the working directory on your computer is called the Working Tree.

Simply put, Git will help users save versions of changes to the source code and it will be easy to restore without having to manually copy and paste somewhere, that version has been backed up. When we discover an error somewhere and want to backup the working session before the error occurs, it will be very simple when we use Git. Another special feature is that a member of the same team when working together can completely track online the changes of other members in each working version without having to sit next to each other, they can also compare those changes and then merge the other member's version into their version. Finally, everyone can put changes to their source code into a source code repository.

Git's versioning mechanism is that it will create a "snapshot" of each file and folder after committing, from which it can allow you to reuse a snapshot that you can understand as a version. This is also the advantage of Git compared to other DVCS when it does not "hard save" data but will save it in snapshot form.

And who is that half-brother?

Github Overview

We have heard of Git and may have used GitHub, but most of us still confuse Git vs GitHub because when we talk about Git, we think of GitHub. That is a misunderstanding because Git, as explained above, is the name of a system model, computers can clone source code from a repository, and GitHub is the name of a company that provides public repository server services, each person can access the homepage website to create an account on it and create their own source repository when working.

Github is highly appreciated and preferred, many big companies put their code repository here: Twitter, Facebook, linkedin. and google is also present on Github.

Home: https://github.com/

Git and GitHub - Using Git the right way to maximize your work Picture 2Git and GitHub - Using Git the right way to maximize your work Picture 2

 

Install Git on Linux

Use without encryption

Step 1 : Install Git

Step 2 : Set up Git user information:

Step 3 : Check the information again:

SSH encrypted link

Generate private key:

Git and GitHub - Using Git the right way to maximize your work Picture 3Git and GitHub - Using Git the right way to maximize your work Picture 3

 

=> Remember the created passphrase .

Result after creating key:

Git and GitHub - Using Git the right way to maximize your work Picture 4Git and GitHub - Using Git the right way to maximize your work Picture 4

 

Add private key to SSH process:

Copy public key

Git and GitHub - Using Git the right way to maximize your work Picture 5Git and GitHub - Using Git the right way to maximize your work Picture 5

 

Go to URL: https://github.com/settings/keys , select New SSH key:

Git and GitHub - Using Git the right way to maximize your work Picture 6Git and GitHub - Using Git the right way to maximize your work Picture 6

 

Paste the public key and select Add SSH key:

Git and GitHub - Using Git the right way to maximize your work Picture 7Git and GitHub - Using Git the right way to maximize your work Picture 7

 

Re-authenticate your Github password:

Git and GitHub - Using Git the right way to maximize your work Picture 8Git and GitHub - Using Git the right way to maximize your work Picture 8

 

Link successful, can commit to Github on local machine without entering username and password.

Git and GitHub - Using Git the right way to maximize your work Picture 9Git and GitHub - Using Git the right way to maximize your work Picture 9

 

Git Operations

Clone

Allows cloning of repository from Github to local machine

or

Git and GitHub - Using Git the right way to maximize your work Picture 10Git and GitHub - Using Git the right way to maximize your work Picture 10

 

Add

While working with Local Repository , create newfile.md file in /root/INTERN/docs path

Add file to Github:

git add newfile.md

or add all added files:

git add *

Test: newfile.md file is waiting for commit

git status

Git and GitHub - Using Git the right way to maximize your work Picture 11Git and GitHub - Using Git the right way to maximize your work Picture 11

 

Commit

Like a final review of changes in the local repository to push to Github

git commit newfile.md -m "Create new file"

or commit all pending files:

git commit -m "Create new file"

  -m: Record comments for a commit

Git and GitHub - Using Git the right way to maximize your work Picture 12Git and GitHub - Using Git the right way to maximize your work Picture 12

 

Push

Push committed files to Github

git push origin master

Git and GitHub - Using Git the right way to maximize your work Picture 13Git and GitHub - Using Git the right way to maximize your work Picture 13

 

Pull

Suppose there is a change made on Github, which needs to be synchronized to Local to work. The pull operation will compare the remote repo on Github and the Local repo, then synchronize to the Local machine.

git pull

Git and GitHub - Using Git the right way to maximize your work Picture 14Git and GitHub - Using Git the right way to maximize your work Picture 14

 

In addition to Git and GitHub, there is also GitLab source code management and is now available on TipsMake's Prebuilt App. Users can integrate up to 50 other convenient working tools with just a few clicks at:  https://bizflycloud.vn/prebuilt-app/apps

Git and GitHub - Using Git the right way to maximize your work Picture 15Git and GitHub - Using Git the right way to maximize your work Picture 15

 

According to TipsMake

4.5 ★ | 2 Vote