# Task: Basic Git & GitHub for DevOps Engineers.

## **What is Git?**

Git is a modern and widely used **distributed version control** system in the world. It is developed to manage projects with high speed and efficiency.

**Git** is an **open-source distributed version control system**. It is designed to handle minor to major projects with high speed and efficiency. It is developed to co-ordinate the work among the developers. The version control allows us to track and work together with our team members at the same workspace.

## **Features of Git**

Some remarkable features of Git are as follows:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682357919809/c5a1ef0a-1744-4916-8a9d-f307054ad71a.png align="center")

## **What is Github?**

GitHub is a Git repository hosting service. GitHub also facilitates with many of its features, such as access control and collaboration. It provides a Web-based graphical interface.

It offers both **distributed version control and source code management (SCM)** functionality of Git. It also facilitates with some collaboration features such as bug tracking, feature requests, task management for every project.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682358017546/3fdcc541-2a22-4170-9cd4-a966275b4eec.png align="center")

## **Features of GitHub**

Some of its significant features are as follows.

* Collaboration
    
* Conversations
    
* Integrated issue and bug tracking
    
* Team management
    
* Git repositories hosting
    
* Project management
    
* Graphical representation of branches
    
* Track and assign tasks
    
* Code hosting
    
    ## **What is Version Control ?**
    
    A version control system is a software that tracks changes to a file or set of files over time so that you can recall specific versions later. It also allows you to work together with other programmers.
    
    The version control system is a collection of software tools that help a team to manage changes in a source code. It uses a special kind of database to keep track of every modification to the code.
    
    ## **What is Version Control? How many types of version controls we have?**
    
* ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682358223571/9575c82d-1d40-4b9e-a12b-4ae4f0e3b3d6.png align="center")
    
    * ### **Centralized Version Control System**
        
    * Centralized version control systems have many benefits, especially over local VCSs.
        
        * Everyone on the system has information about the work what others are doing on the project.
            
        * Administrators have control over other developers.
            
        * It is easier to deal with a centralized version control system than a localized version control system.
            
        * A local version control system facilitates with a server software component which stores and manages the different versions of the files.
            
    
    ![Git Version Control system](https://static.javatpoint.com/tutorial/git/images/git-version-control-system-1.png align="left")
    
    ### **Distributed Version Control System**
    
    In a Distributed Version Control System (such as Git, Mercurial, Bazaar or Darcs), the user has a local copy of a repository. So, the clients don't just check out the latest snapshot of the files even they can fully mirror the repository. The local repository contains all the files and metadata present in the main repository.
    
    ![Git Version Control system](https://static.javatpoint.com/tutorial/git/images/git-version-control-system-2.png align="left")
    
    ## Why we use distributed version control over centralized version control?
    
    <table><tbody><tr><td colspan="1" rowspan="1"><p><strong>Centralized Version Control System</strong></p></td><td colspan="1" rowspan="1"><p><strong>Distributed Version Control System</strong></p></td></tr><tr><td colspan="1" rowspan="1"><p>In CVCS, The repository is placed at one place and delivers information to many clients.</p></td><td colspan="1" rowspan="1"><p>In DVCS, Every user has a local copy of the repository in place of the central repository on the server-side.</p></td></tr><tr><td colspan="1" rowspan="1"><p>It is based on the client-server approach.</p></td><td colspan="1" rowspan="1"><p>It is based on the client-server approach.</p></td></tr><tr><td colspan="1" rowspan="1"><p>It is the most straightforward system based on the concept of the central repository.</p></td><td colspan="1" rowspan="1"><p>It is flexible and has emerged with the concept that everyone has their repository.</p></td></tr><tr><td colspan="1" rowspan="1"><p>In CVCS, the server provides the latest code to all the clients across the globe.</p></td><td colspan="1" rowspan="1"><p>In DVCS, every user can check out the snapshot of the code, and they can fully mirror the central repository.</p></td></tr><tr><td colspan="1" rowspan="1"><p>CVCS is easy to administrate and has additional control over users and access by its server from one place.</p></td><td colspan="1" rowspan="1"><p>DVCS is fast comparing to CVCS as you don't have to interact with the central server for every command.</p></td></tr><tr><td colspan="1" rowspan="1"><p>The popular tools of CVCS are <strong>SVN</strong> (Subversion) and <strong>CVS</strong>.</p></td><td colspan="1" rowspan="1"><p>The popular tools of DVCS are <strong>Git</strong> and <strong>Mercurial</strong>.</p></td></tr><tr><td colspan="1" rowspan="1"><p>CVCS is easy to understand for beginners.</p></td><td colspan="1" rowspan="1"><p>DVCS has some complex process for beginners.</p></td></tr><tr><td colspan="1" rowspan="1"><p>If the server fails, No system can access data from another system.</p></td><td colspan="1" rowspan="1"><p>if any server fails and other systems were collaborating via it, that server can restore any of the client repositories</p></td></tr></tbody></table>
    
    ## **Step-1 Install Git on your CentOs Linux Instance:**
    
    `1. sudo yum install git`
    

# **Step-2 Check Git and its Version:**

`which git`

`git --version`

# **Step-3 Configure Username and Email id**

`config --global` [`user.name`](http://user.name)

`git config --global` [`user.email`](http://user.email) `<`[`Email.id`](http://Email.id)`>`

## **Step-4 Checking details:**

`git config --list`

## **Step-5 Creat Account on Git hub :**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682358622806/7299aede-1533-4d69-9403-d7c4a41f970e.png align="center")

## **Define Workspace, Staging area and repositories in Git:**

1. **Workspace:** The workspace, also known as the working directory, is the directory on your local machine where you make changes to your files. This is the place where you modify, create, or delete files as you work on your project.
    
2. **Staging Area:** The staging area, also known as the index, is an intermediate step between the workspace and the repository. When you make changes to your files in the workspace, you can add them to the staging area to prepare them for committing. The staging area allows you to review and select the changes you want to commit and exclude any changes that you don't want to commit.
    
3. **Repository:** A repository is the place where Git stores the history of your project. It contains all the versions of your files and their complete change history. You can have multiple repositories for a project, including local repositories on your machine and remote repositories on servers.
    

**Step-1 Creat a Directory and Initializes it :**

![How to Resolve Merge Conflicts in Git? | Simplilearn [Updated]](https://www.simplilearn.com/ice9/free_resources_article_thumb/pull-push.JPG align="left")

`git init`

`git init <name of directory> , if you are not in working directory`

**Step-2 Creat a file and add it to local repo:**

`touch devops`

`git add . <file name>`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682358890007/c3189598-5c11-4b1a-bd19-2a0dbef893a8.png align="center")

**Step-3 Now if you your file is ready to commit , you can see the status as well.**

`git status`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682359140914/f2095a36-ca51-4f43-b9e9-b47ff9b4dc79.png align="center")

**Step-4 You can see here this file is now ready to commit. so just commit it :**

`git commit -m "Your message"`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682359273935/a59caf3f-5026-43a6-8df3-33ec3e30b8ae.png align="center")

  
**Step-5 Just add the central repository here so that you can push your file in Central repo:**

**At first just copy the link of your central repo on Github account:**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682359400029/3a5c7ce9-f463-4e55-b77c-85b15146a3c5.png align="center")

**Execute command:**

`git remote add origin <https link>`

**Step-6 Now try to push it into central repo:**

`git push -u origin master`

`git push -u <branch name> , if you are in branch`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682360202000/d0350b35-bbdd-4953-be2e-261835f46653.png align="center")

**it will ask for username and password just go to Github account and create token and use it for both username and password:**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1679830930486/1d3bb857-f335-4835-960f-145ce6d8498b.png?auto=compress,format&format=webp&auto=compress,format&format=webp align="left")

go to &lt;setting&gt; than &lt;developer setting&gt;

![Creating and Uploading a GitHub Project From GUI](https://thecustomizewindows.com/wp-content/uploads/2013/02/Creating-and-Uploading-a-GitHub-Project-From-GUI.png align="left")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1679830987175/fdf10140-3e4b-49c8-92b6-3e7ee85d861b.png?auto=compress,format&format=webp&auto=compress,format&format=webp align="left")

**Generate classic token :**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682360202000/d0350b35-bbdd-4953-be2e-261835f46653.png align="left")

**Now you can check it onto your Git hub Account:**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682360414162/8ba6922a-eca2-431e-80e3-aed63a658bd3.png align="center")

**To pull it from github use following command:**

`git pull origin master`

**Note: At present we are on master so we are using origin master, now what if we creat a branch and then try to push it into github lets see:**

## **Creating Branch :**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1679834563991/3358fa37-1364-47d0-b350-2e45b66d21a7.png?auto=compress,format&format=webp&auto=compress,format&format=webp align="left")

In Git, a branch is a lightweight movable pointer to a commit. Branches are used to create a separate line of development, allowing changes to be made to a codebase without affecting the main codebase until the changes have been tested and merged.

Creating a new branch in Git is a quick and easy process. When you create a new branch, you essentially create a new pointer to the current commit that you are working on. You can then make changes to the codebase, and all of those changes will be made on the new branch.

**Branch Creation:**

`git branch <branch name>`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682360602992/0d1a495f-f21d-403c-b574-cd461f26e6ec.png align="center")

**To enter into branch which you have created and to check where you are at present:**

`git checkout <branch name>`

`git branch`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682360991605/115a4eef-c5f1-4f6f-a3cb-288ebdf42121.png align="center")

**Here ,You can see at first , I was in master branch denote with \* then I switch into branch1 using the checkout command:**

**now create a file in it and add it to commit**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682361173819/d5c8ee42-05dc-460e-880f-22a8d3cb0d23.png align="center")

**Now just try to push my new branch into Central Repository:**

`git push -u origin <branch name>`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682361376992/d085be10-a062-4df1-8bb7-f0c297eee406.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682361485655/5401655b-42f2-4482-8ec6-dc374d55a51d.png align="center")

**You can see it in your Github Account:**

Like share Subscribe to my channel

### **Subscribe to my newsletter**

Read articles from **Uzairbagwan's blog** directly inside your inbox. Subscribe to the newsletter, and don't miss out

#devops #trainwithshubham #linux #90daysofdevops #aws #learn
