This weekend, while you're doing your mini-projects we are going to get some practice with 2 things.
- Hound - A tool that monitors your pull requests and will notify you of syntax and style errors within your code.
- Rebaseing - a git tool that will allow you to clean up your commit messages.
- Go to HoundCI.com and click "Sign in with github"
- Activate Hound on your mini-project repository
- Now, Hound will monitor your pull requests and notify you of any violations in your code.
- Fix the violations, commit, push to branch, and check the pull request again to see if there are any additional violations. Repeat this process until Hound is happy with your code.
- Don't merge your pull request yet!
Second - Rebase your hound commits to have a clean organized commit history before you merge the branch
- When you rebase you have many options you can perform. We are going to squash all our hound commits for a specific pull request into one, all encompassing commit. Remember to use good commit message practices and be detailed as to what the 'new' single squashed commit did. In other words - condense the information from all the commits you are squashing into the one commit.
- Before you merge your feature branch with master -
git rebase -i master
- now you will get a screen in you're terminal that will allow you to choose what you want to do with your commits. You will see this in your terminal unless you overwrote your default editor in your profile.
- Currently before all the commits you will see the word
pick
- Since we are going to
squash
our commits into one, change pick to squash. Squash will take a commit and squash in into the one above it. So if you have multiple commits you want to squash into one change pick to squash for all but the top commit. - To edit in the terminal we will use VIM commands. Press
i
to get into INSERT mode. Be careful to only change the work pick to squash. - Once you've marked the commits you want to squash hit the 'esc' key to exit INSERT mode.
- Now type
:wq
this stands for 'write and quit'. This should send you to another VIM screen that will let you edit all the commits. You should see an explanation about what to do and how to do it. Again you can enter INSERT mode by typingi
- Go ahead and edit your commit message to you have a 'subject line' and then the 'body' of the commit. Delete all the old messages below into one single message.
- When you are done editing your new single commit hit the 'esc' key again to exit INSERT mode. Type
:wq
- Now you can push to the your branch and merge your pull request. YOU WILL NEED TO
git push origin branch_name --force
- If you do not want to push with force you can alternatively checkout a new_feature_branch that is just for the rebaseing of the feature branch, squash your commits then make a pull request for the new_feature_branch and merge this new_feature_branch instead of the original feature_branch. Make sure you close the pull request from the original feature_branch without merging it to master.
P.S. Hound will frustrate you - but it knows best.