← iOS

Best Practices for Git Usage

This wiki originates from our Code Reading on Git and Best Practices on 2016-02-10. Feel free to add more git Best Practices and tips for more effectively using git and related clients.

Git clients

This is a list of clients that the team is currently using. Knowledge of basic command line usage is a must. GUI clients can be helpful for looking at diffs and staging when unrelated changes are mixed in the code.

There are other clients out there. Some for pay that seem promising, but I have no experience with any.

Staging and breaking up commits

Each commit should have a single responsibility. Strive for the minimum viable commit you can make to capture the changes you just made.

Whenever possible, do not stage unrelated changes in the same commit. Err on the side of smaller, atomic commits, even ones that are breaking, if it makes following what you’re trying to do clearer.

I often make commits that prepare for future commits.

Training and Onboarding

We should be introducing our team’s best practices when a new person hires on. This wiki is a start.

Commit message best practices

The first link pretty much sums it up: The first line of your commit message should be 50 characters or less. This is what shows up in git log and in the GitHub summary. Follow this by a blank line, and then a summary of why you made the changes you did. Why is more important than what. What should be obvious from the diff.

If your commit summary has the word AND, your commit is probably not atomic enough.

Some useful comments on commit message style:

Rebasing

We should all be rebasing to master before the first push to GitHub. But never rebase after a branch has been pushed to GitHub. This rewrites the commit history.

Merge conflicts

SourceTree has a nice feature that will launch an external merge tool and allow you to resolve your conflicts. By default it uses FileMerge, which is included in the Xcode install.

wiki docs

We need to document this in the wiki so we’re all on the same page, and we can onboard new people more easily.

Notes from the Code Reading

If something you said isn’t captured here, or was captured incorrectly, please make it right. Please expand, improve, reformat….

Chris

git extras

Some useful git-extras commands

undo
pr
delete-merged-branches
merge-into
changelog
summary
effort

Allyn

uses GitHub Desktop to review PR changes you can add new commands to git via your .bashrc or .profile or whatever (need to have Allyn enter some more info about how this works - I didn’t catch the beginning of how it hooks up to git)

Coury

what’s a better way to undo commits?

Steve

Moving commits from one branch to another

git patch
git am

Patrick

StackOverflow tends to have good answers to common git problems

Randy

Tower has a free eBook & video course for learning Git. https://www.git-tower.com/learn/