Five birds one stone
Published: 2021-10-16 02:50:25

We're all very familiar with the phrase *"to kill two birds with one stone."* This week I learned I could kill more than two birds with one stone by using git rebase. 

![](https://media.giphy.com/media/15zg4tmiT44N2/giphy.gif)

### Background
I've used this command previously and it resulted in a **huge** mess where I pulled in a bunch of commits that I did not make in a branch, and then all those commits got added to my PR.

This week I learned exactly why that happened by actually understanding what git rebase does.

### Lab 05
For Lab 5 I was more than happy to see we could use the time to refactor our code for the static site generator(SSG). I discussed my struggles setting up the SSG in [release 0.1](https://dev.to/amasianalbandian/release0-1-ho6) and with that came a lot of bugs and what I will refer to as "working" code(to say that it could be better is an understatement). 

After my experience from release0.1, I was lucky and grateful to have David and Reza log in some issues on top of the ones I discovered. I decided to use these to refactor the code. 

### Commits
Below are the issues I decided to use for commits to then squash.
###### [Adding protection to invalid arguments in the cli](https://github.com/AmasiaNalbandian/static-site-generator/issues/6)
###### [Fixing the mismatch license](https://github.com/AmasiaNalbandian/static-site-generator/issues/11)
###### [Fixing incorrect variable types](https://github.com/AmasiaNalbandian/static-site-generator/issues/12)
###### [Improve error handling](https://github.com/AmasiaNalbandian/static-site-generator/issues/13)

### Outcome
After creating commits for each of the issues, I then ran an *interactive* git rebase by using the following command: 
``` git rebase main -i```

To my surprise there was a lot of interaction in the CLI through [Vi](https://www.howtogeek.com/102468/a-beginners-guide-to-editing-text-files-with-vi/), and it threw me off as I tried to understand what I was supposed to do. This is the image of the message in the editor: 
![Image of editor after running interactive rebase command](https://i.imgur.com/OF0idGj.png)


After a few seconds I realized what I had to do was change the text from `pick` to `squash` to squash all five commits into one. 

![Image of squash text in editor](https://i.imgur.com/vI0adCs.png)

Once this was done I received the following: 

![Image of result after rebasing and squashing five commits](https://i.imgur.com/uuWEQFE.png)

I then went ahead and I checked out back to main, and merged my changes from the refactoring branch. I learned another thing here: My local commits from the refactoring branch were able to be merged into the main branch which was in GitHub. I had never tried this before without putting both branches up on GitHub, which explains why I was probably a bit shocked.

Lastly, I wanted to attach this image below which would demonstrate how a rebase works. 
![](https://docs.gitlab.com/ee/topics/git/img/git_rebase_v13_5.png)

And another image here, which explains the difference between a rebase and a merge (as I know most people use these methods to grab latest commits from main branches in their feature branch.... *cough cough* me).  
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gv60fpe4pa33ryphuqvw.png)