# Day 13 - Advance Git & GitHub for DevOps Engineers

# Git Branching

Git branching means you're making a **separate line of work** in your project — like creating a **copy** of your project to work on something new **without changing the original**.

```bash
main
  |
  o---o---o-----------------o   ← main
          \               /
           o---o---o---o     ← feature1
```

# Git Revert and Reset

Git reset and git revert are two commonly used commands that allow you to remove or edit changes you’ve made in the code in previous commits. Both commands can be very useful in different scenarios.

# Git Rebase and Merge

## What Is Git Rebase?

Git rebase is a command that lets users integrate changes from one branch to another, and the commit history is modified once the action is complete. Git rebase helps keep a clean project history.

## What Is Git Merge?

Git merge is a command that allows developers to merge Git branches while keeping the logs of commits on branches intact. Even though merging and rebasing do similar things, they handle commit logs differently.

# Task 1: Feature Development with Branches

1. **Create a Branch and Add a Feature:**
    
    Add a text file called `version01.txt` inside the `Devops/Git/` directory with “This is the first feature of our application” written inside.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1749660742009/0e6f1ed0-bace-49c4-ad27-8819b2e9f4ba.png align="center")
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1749660762773/6888f069-6d03-409d-89d2-9b78cffd230b.png align="center")
    
    Create a new branch from `master`.
    
    ```bash
    git checkout -b dev
    ```
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1749660898391/0ad6fe6e-88fe-4c54-89be-e661aeb9e124.png align="center")

Commit your changes with a message reflecting the added feature.

```bash
git add Devops/Git/version01.txt
git commit -m "Added new feature"
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1749660925516/76db2019-21a6-4104-9c25-f4bf8152dc01.png align="center")

2. **Push Changes to GitHub:**
    

* Push your local commits to the repository on GitHub.
    
    ```bash
    git push origin dev
    ```
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1749660954957/9a31a597-16f2-4c55-a56c-378125353f5e.png align="center")
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1749660973720/568519fb-996b-4fb0-b5f4-d121d5881f97.png align="center")
    

3. **Add More Features with Separate Commits:**
    

* Update `version01.txt` with the following lines, committing after each change:
    
    * 1st line: `This is the bug fix in development branch`
        
        ```bash
        echo "This is the bug fix in development branch" >> Devops/Git/version01.txt
        git commit -am "Added feature2 in development branch"
        ```
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1749698554565/3de0ea30-0a14-48f3-b2fc-e87c010ea9d4.png align="center")
        

2nd line: `This is gadbad code`

```bash
echo "This is gadbad code" >> Devops/Git/version01.txt
git commit -am "Added feature3 in development branch"
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1749698577821/6c4a6591-86b2-4865-8a3a-1cf945308311.png align="center")

3rd line: `This feature will gadbad everything from now`

```bash
echo "This feature will gadbad everything from now" >> Devops/Git/version01.txt
git commit -am "Added feature4 in development branch"
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1749698593073/bfe2543d-9562-42ce-b5a6-9d0d25b67704.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1749698613087/c01310ea-bf7e-4f01-9fb9-64c9933ff1e0.png align="center")

# Task 2: Working with Branches

1. **Demonstrate Branches:**
    

* Create 2 or more branches and take screenshots to show the branch structure.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1749698723037/66fbf47b-42b0-4fde-8811-9cfdd1ed3f4f.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1749699885593/34f92568-379c-4fd1-80a0-351acb11bce6.png align="center")

2. **Merge Changes into Master:**
    

* Make some changes to the `dev` branch and merge it into `master`.
    
    ```bash
    git checkout dev
    git merge dev
    ```
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1749699719781/63d79ff1-8dda-4300-a226-f1b3a05073bf.png align="center")

3. **Practice Rebase:**
    

* Try rebasing and observe the differences.
    
    ```bash
    git rebase main
    ```
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1749699660317/9dd37754-ee6d-4e4e-9f1d-605b64f3beaa.png align="center")
