# Advance Git & GitHub for DevOps Engineers: PART-01

**Branches allow you to develop features, fix bugs, or safely experiment with new ideas in a contained area of your repository.**

**Revert**  
`The revert command is used to create a new commit that undoes the changes introduced by a previous commit. It creates a new commit that reverses the changes from the specified commit. It is often used in the following situations:   Undoing Mistakes:- If you or your teammate made a mistake and you want to revert the changes introduced by that commit without removing that commit from the commit history.   Reverting Feature/Branch:- If you have a feature with multiple commits and you decide to remove or undo the entire feature, you can use revert to create a new commit that undoes all the changes introduced by that feature branch.   Public Repository:- if you are working on a repository with multiple contributors or a public repository, it is generally considered best practice not to rewrite the commit history. Using "revert" allows you to safely undo the changes without affecting other contributors or users who may have already pulled the changes.`  
  
`Steps to create a branch and perform revert, reset and merge functions`

`Add a text file called version01.txt inside the Devops/Git/ with “This is the first feature of our application” written inside.`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690783842435/425bc2a7-d93f-42f5-9006-7ce1406601e3.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690783898271/115e970a-03da-4896-9c06-2cc23b3ad213.png align="center")

`This should be in a branch coming from the master`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690802823833/2af5a937-ab45-48bc-b6d8-39df8bb8317c.png align="center")

`switch to the dev branch ( Make sure your commit message will reflect as "Added new feature").`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690802874484/01b31523-3840-4ff6-9d71-ef2cd0ab4d20.png align="center")

`version01.txt should reflect at the local repo first followed by the Remote repo for review.`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690786300911/548ce745-7b3f-4604-bf4e-d8b3856787aa.png align="center")

`Before pushing changes:-`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690802960845/dbac9584-8bb0-4482-8886-c5d0faccd236.png align="center")

`After pushing changes to the repo:-`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690803314121/95e01f66-5ae9-43db-9a6e-fb2ece81b7fb.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690805169655/8ffe972b-5041-43f3-9cf2-3f555e3e1b6d.png align="center")

`Add a new commit in the dev branch after adding the below-mentioned content in Devops/Git/version01.txt: While writing the file make sure you write these lines`

* `1st line>> This is the bug fix in the development branch`
    
* `Commit this with the message “ Added feature2 in development branch”`
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690805270428/9f42a372-7dfe-4022-9787-25fdbadd3819.png align="center")
    
* `2nd line>> This is gadbad code`
    
* `Commit this with the message “ Added feature3 in the development branch"`
    
* ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690805368330/fa05b59d-08a5-469b-b9a5-58dffd70eb4c.png align="center")
    
    `3rd line>> This feature will gadbad everything from now.`
    
* `Commit with the message “ Added feature4 in the development branch"`
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690805452425/9c6fd362-7eca-4126-93da-ed1289ea2aa8.png align="center")
    
    `Restore the file to a previous version where the content should be “This is the bug fix in the development branch”. Here, we use to revert to restore the file.`
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690805805619/38cdfd09-645d-47a6-9977-9928119d0bfb.png align="center")
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690805884889/2353b135-7817-4b3b-bf12-3a5898f3aa89.png align="center")
    

## Reset

`Git Resst - In Git, the Reset command allows you to move the specific branch's head to a specific commit, effectively changing the branch history and staging area without creating new commits.   Syntax:- git reset <commit>   <commit>: The commit you want to reset to. It can be specified as a commit hash, branch name, or a relative reference (e.g., HEAD~1 to refer to the commit before the current HEAD)`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690807264299/06929a71-a490-4093-b565-3e60255e8905.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690810709188/01141928-620e-4f72-bd36-e3bcc5538b9f.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690810752554/9e8b4505-aef3-4dbe-afd2-c66d93b5d33a.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690810778933/c50d623d-21e5-4cc5-9cef-59bb2d5bb8db.png align="center")

* ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690810876747/96cf1b17-0aa7-461a-a488-5627990d5ce0.png align="center")
    

## Merge

`The git merge command in Git is used to integrate changes from one branch into another. It combines the changes made in one branch and applies them to another branch. The basic usage of the git merge command is as follows:`

```bash
git merge <source_branch>
```

`<source_branch>: This is the branch that contains the changes you want to merge into the current branch (often the branch you're currently on).`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690814065813/513cc469-7b50-4136-b7cd-c7193472e1b7.png align="center")
