I can't Git no, satisfaction
Tags: beginners, github, vcs
Published: 2021-09-15 03:30:23

As developers, we break and fix code all day. But there might be a time when you completely mess your code up. That's when a VCS (Version Control System) comes in handy. A VCS keeps track of all the changes you make to your code, as long as you are committing often. The most popular VCS we use is [Git](https://git-scm.com/book/en/v2/Getting-Started-About-Version-Control). So if you get to a point where you can't save your code, you can use your VCS and revert back to any past commit.

![Git ctrl-z meme](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ak44q8irmeg2w20sl0l7.jpeg)

A git workflow I really like is the **Feature Branch Workflow**. The idea behind this workflow is that each feature development will be done on dedicated branches. This allows each developer to work on their own feature without worrying about other developers or disturbing the main branch.

Another advantage of this workflow is being able to utilize pull requests. To merge your branch to the main branch, you initiate a pull request. This allows other developers to look over your code, discuss, even ask you to make changes and then finally sign-off that it's ready to be merged to the main branch.

<br>
#<center>. . .
<br>
#Feature Branch Workflow

With this workflow, you will be making a branch for every feature you are developing. Then when you complete the feature, you will submit a pull request to have it added to the main branch. This might seem tedious, why not just have your own dedicated branch where you work on different features? Performing pull requests and merging each feature will make it easier to review code and resolve merge conflicts as there won't be hundreds of lines of code to sort through. Here's how this workflow will look.

##First 
you want to make sure you have the latest code to create your branch.
```react
git checkout main
git pull origin
git reset --hard origin/main
```
This switches your local repo to the main branch, pulls the latest code from origin, then resets the HEAD of your local copy to match origins.

##Then
create a new branch for the feature you are building.
```react
git checkout -b login-page
```
This creates a branch called **login-page** and switches you to it at the same time.

##And then
push your new branch to your remote repository so you will have a backup and if you are collaborating, other devs will have access to your changes.
```react
git push -u origin login-page
```
The **-u** flag sets this branch as your remote tracking branch. Meaning you can just type **git push** to push up your changes.

##As
you work, remember to commit often so you can revert back if needed.
```react
git status
git add .
git commit -m "descriptive commit message"
git push
```

##Finally
when you're done with your feature, do a final **git push** and create a pull request on your remote repository to start the process of getting your branch merged into the main.
![Github pull request](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mftpkzx25ymm80gbnt8o.png)

![Github open pull request](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2rayvsfkp6jlcpzh9sjt.png)
It will tell you if you are able to merge into the main so you can take care of any merge conflicts.

![Github pull request interface](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qcqezyayl6mmvpafbgrm.png)
Once you create the pull request, other devs can make comments, request changes, and eventually **merge pull request** which will merge your branch into the main.

![Github pull request merged](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ri9dd3fvjnagnljhtwhb.png)
Now your branch can be deleted and you can start on your next feature!

#Conclusion
I really like this workflow because it keeps the main branch clean. If you aren't using a git workflow with your team I recommend trying this out as it will help prevent/minimize the git issues we all run into. Happy coding!