Skip to content

Instantly share code, notes, and snippets.

@jasonnoble
Forked from Carmer/Rebase_the_Hound.md
Last active November 6, 2015 21:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasonnoble/5e9f5e3bc829c3f13a60 to your computer and use it in GitHub Desktop.
Save jasonnoble/5e9f5e3bc829c3f13a60 to your computer and use it in GitHub Desktop.

Let us Rebase

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.
  • Rebasing - a git tool that will allow you to clean up your commit messages.

What are we going to do?

First - Integrate Hound in your project.

  • 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 style 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.

How do we rebase -

  • Before you merge your feature branch with master - git rebase -i master
  • You will be presented with 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
  • Leave the first line as pick
  • Change all the other lines to squash. This will squash our commits into the first commit. ** To edit in the terminal we will use VIM commands. Press i to get into INSERT mode. ** Make sure the first line says pick ** Make sure all the other lines say 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 to edit the now squashed commit. The VIM window will have all of the commit messages combined so that you can edit the new commit message. You should see an explanation about what to do and how to do it. Again you can enter INSERT mode by typing i
  • Go ahead and edit your commit message to have a 'subject line' and then the 'body' of the commit. If you want to keep the old commit messages, convert them to bullet points by adding * to the beginning of the line.
  • When you are done editing your commit message hit the 'esc' key again to exit INSERT mode. Type :wq

If you did everything correctly you should see a message that says you have successfully rebased.

  • 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.

Good luck and happy rebasing.

P.S. Hound will frustrate you - but it knows best.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment