-
Notifications
You must be signed in to change notification settings - Fork 5
Git Hygiene
Some guidelines for keeping your code in shape
-
Use the diagnostics from
gulp dev
. The code checks that run on Travis are run every time you save a file. Look at what your runninggulp
says when you save. If there are issues, you can fix them then. Before doing a commit, stop and restart gulp, and watch its output. It will look at all your files and report on any problems. -
Squash commits. Each PR should ideally be one commit. This makes rebasing (see below) easier, and keeps the history clean. You may need to make interim commits while you're working. That's fine. When it's time to issue a PR, do
git log
and find the commit just before the first commit you made for this batch of work. It will have a long ID. Copy the id, and dogit rebase -i
longid
That will give you an editor window in which you can replacepick
withf
for all your commit lines except the initial commit. Save the file and you'll have just one commit.
Also useful: the--amend
option togit commit
will add your changes to the previous commit instead of making a new one. -
Rebase to master. When a PR is merged to master, any active branches will be out of date and not ready to merge. Do not merge master into your branch. Instead, make sure your
master
branch is up to date:
git checkout master
git pull
Then rebase your branch on master
:
git checkout _my-branch_
git rebase master
If there are any conflicts you need to resolve, it will suspend the rebase for you to fix them. Then do:
git add .
git rebase --continue
It will do one round of conflict-checking for each commit in your branch, so you see why it's helpful to have squashed your commits down to one. When the rebase is done, your branch will be up to date with master and ready to issue a PR if you are.