# Day 3 Update: 90 Days of DevOps Challenge Progress

# Git and GitHub for DevOps: Essential Concepts and Commands

As I continue my DevOps learning journey, one of the core tools I’ve been diving into is **Git** and its counterpart, **GitHub**. Whether you're managing personal projects or working on enterprise-level applications, these tools form the backbone of source code management. In this blog, I'll walk you through the key concepts, commands, and methods to integrate Git and GitHub into your workflow.

## What is Git?

Git stands for **Global Information Tracker**. It's a distributed version control system (VCS) that helps developers track changes in their code, collaborate with others, and manage different versions of a project.

### Key Concepts in Git:

1. **History**: Git was created by **Linus Torvalds** to track versions of the Linux kernel. He needed a reliable way to manage changes in a distributed manner.
    
2. **Version Control**: The primary use of Git is to track code versions. You can see what changes were made, when, and by whom.
    
3. **Untracked vs Tracked Files**:
    
    * **Untracked**: Files that are not yet being tracked by Git. These files haven't been added to version control.
        
    * **Staged**: Files ready to be committed to version control.
        
    * **Tracked**: Files that are already being tracked and can be reverted to previous versions if necessary.
        

---

## Common Git Commands

Here are some essential Git commands that you'll use frequently in your day-to-day work:

### 1\. `git init`

This initializes a new, empty Git repository. Every Git project starts with this command.

```bash
git init
```

### 2\. `git add`

This command stages untracked files, preparing them to be committed.

```bash
git add <filename>
```

### 3\. `git commit`

Commits the staged files to the repository, creating a snapshot of the current state of the project.

```bash
git commit -m "Your commit message"
```

### 4\. `git restore`

If you delete a file by mistake, Git provides the ability to restore it:

```bash
git restore <filename>
```

### 5\. `git log`

Displays the commit history of your repository. You can see what changes were made, by whom, and when.

```bash
git log
```

---

## Git Branching

Branching is one of the key features of Git that makes it so powerful for development teams. It allows you to work on different versions of a project simultaneously.

### Types of Branches:

* **Main** (formerly known as **Master**): The primary branch where all production-ready code is merged.
    
* **Feature Branches**: Used for developing new features.
    
* **Hotfix Branches**: For urgent bug fixes.
    

### Commands Related to Branching:

* **Create a new branch**:  
    Use this to create a new branch and switch to it:
    
    ```bash
    git checkout -b <branch_name>
    ```
    
* **Switch between branches**:  
    If you want to switch to another branch, use:
    
    ```bash
    git checkout <branch_name>
    ```
    
* **Merge branches**:  
    To combine changes from one branch into another, first switch to the branch you want to merge into, then use the following command:
    
    ```bash
    git merge <branch_name>
    ```
    

---

## Introduction to GitHub

While Git is the tool for managing versions of your code, **GitHub** is a platform where you can host, share, and collaborate on your repositories. GitHub provides a UI for Git commands and enables remote collaboration on projects.

### Common GitHub Commands:

### 1\. `git clone`

Clones a repository from GitHub to your local machine:

```bash
git clone <repository_link>
```

### 2\. `git fork`

Forking allows you to copy someone else's repository into your own GitHub account. This is useful when contributing to open-source projects.

### 3\. `git remote -v`

This command shows the remote repository linked to your local Git repository.

```bash
git remote -v
```

---

## Connecting GitHub with Your Editor or Terminal

There are two primary methods to connect your local Git repository to GitHub for pushing code:

### 1\. Using HTTPS with Personal Access Token (PAT)

This is a convenient method for pushing code without logging in every time.

```bash
git remote set-url origin https://<PAT>@github.com/<your_destination_public_repo>.git
```

### 2\. Using SSH (Industry Standard)

SSH is considered more secure and is widely used in production environments.

```bash
git remote set-url origin <Your_repo_ssh_code_link>
```

Before using SSH, you need to generate an SSH key on your local machine and add the public key to your GitHub account. Here’s how you can generate an SSH key:

```bash
ssh-keygen
```

Once generated, add the public key to your GitHub account to establish a secure connection.

---

## Pushing and Pulling Code

After making changes to your local repository, you'll need to push these changes to GitHub or pull updates made on GitHub to your local machine.

### Push Code to GitHub:

```bash
git push origin <branch_name>
```

### Pull Code from GitHub:

```bash
git pull origin <branch_name>
```

---

## Final Thoughts

Understanding Git and GitHub is crucial for anyone in the world of DevOps. From version control to collaboration, these tools play a vital role in the software development lifecycle. Whether you're working on small projects or contributing to larger codebases, mastering Git commands and GitHub workflows will undoubtedly enhance your productivity and streamline your development process.

If you're also passionate about learning DevOps, follow me on this journey as I dive deeper into the tools and practices that make DevOps a game-changer in the tech industry.

---

That’s a wrap on this blog! If you have any questions or suggestions, feel free to drop a comment.

#DevOps #Git #GitHub #VersionControl #SSH #BranchingStrategies #ContinuousLearning #90DaysOfDevOps
