# Basic Git & GitHub for DevOps Engineers

## What is Git?

`Git` is a popular and widely used version control system that allows developers to keep track of changes made to their code over time, collaborate with others, and work on multiple versions of their code.

## What is a GitHub?

`GitHub` is a web-based platform that provides hosting for Git repositories and offers additional features such as issue tracking, pull requests, and code reviews. It allows developers to share and collaborate on their code with others.

## What is Version control?

`Version control` is a system that allows developers to keep track of changes made to their code over time, and enables them to revert to previous versions or collaborate with others on the same codebase.

### Types of Version Controls

There are two main types of version control systems: `centralized` and `distributed`.

* `Centralized version control` systems store code in a central server, while distributed version control systems create multiple copies of the repository on different computers.
    

* `Distributed version control` offers several advantages over centralized version control, such as the ability to work offline and make commits locally, easier collaboration and branching, and a faster workflow.
    

### Everything Combined

Git is a version control system that allows developers to keep track of changes made to their code, GitHub is a platform that provides hosting for Git repositories and additional features, version control is a system that allows developers to manage and track changes made to their code over time, there are two main types of version control systems (centralized and distributed), and distributed version control offers several advantages over centralized version control.

### 10 Basic git Commands

1. `git init`: Initializes a new Git repository in your current working directory.
    
2. `git add`: Adds changes made to your code to the staging area, which prepares them to be committed.
    
3. `git commit`: Commits changes to the repository and creates a new snapshot of the code.
    
4. `git status`: Shows the current status of the repository, including which files have been modified or added, and which files are ready to be committed.
    
5. `git log`: Shows a history of all the commits made to the repository, along with their messages and other details.
    
6. `git branch`: Lists all the branches in the repository, and shows which branch you are currently on.
    
7. `git checkout`: Switches to a different branch or a specific commit.
    
8. `git pull`: Updates the local repository with changes made in the remote repository.
    
9. `git push`: Sends changes made locally to the remote repository.
    
10. `git clone`: Creates a copy of a remote repository on your local machine.
    

Git has many more powerful features and commands that can help you manage your code and collaborate with others.

### Task 1: New Repository in Github and Cloning it locally.

A GitHub account already exists. I created the repository Day-8-task on git. I will clone the repo and make changes to the README.md file and commit the changes to GitHub.

* To clone the repository `git clone` followed by the repository link
    

`git clone` [`https://github.com/Arafique458/Day-8-Task.git`](https://github.com/Arafique458/Day-8-Task.git)

* To configure the credentials, I will be using a Secret Access token to connect to the repository.
    

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

`git config --global` [`user.email`](http://user.email) `"arafique458@gmail.com`

* To access the cloned directory
    

`cd Day-8-task`

* To make changes to the README.md file
    

`vim README.md`

* After making changes check the status of the file modified.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1679853787414/886d65a0-0f0b-449b-8935-0292ff11e7d4.png align="center")

* To stage, the changes `git add .` (this will stage all the files in the directory or we can specify the file want to stage)
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1679853927671/315283e2-2d2a-4811-aad6-b53c5b81b232.png align="center")
    
    * To commit the change we made to the README.md file `git commit -m "what were changes"`
        

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1679854077422/ce0a6f8d-7432-423b-bf32-1724a0b6c0e3.png align="center")

* To push the changes to the main repository in the GitHub `git push origin main` (I was prompted to enter credentials, I used the email address of the git hub and Access token)
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1679854353568/d021d09e-7e04-4db3-9c7d-4e0138166d41.png align="center")

### Task 2: File in the repository changed and commit was made in the repository using Git

**GitHub repository before making a commit**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1679854442102/41b24a52-99eb-4ef0-abe4-670379316d92.png align="center")

**GitHub repository before making a commit**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1679854505740/29ba22f8-f7cb-47fc-bae5-e1116a008a91.png align="center")

### Task 3: Pushed Changed / Commit Screenshot of GitHub repository

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1679854695714/0a9c569d-f0a1-4245-94e5-a7ee2723cd00.png align="center")
