Skip to content

Instantly share code, notes, and snippets.

@Carmer
Last active November 6, 2015 21:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Carmer/9a940af050a73e3fe651 to your computer and use it in GitHub Desktop.
Save Carmer/9a940af050a73e3fe651 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.
  • Rebaseing - 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 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 are going to rebase -

  • 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 typing i
  • 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

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

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