A guide for programming within version control.
- General Guidelines
- Writing a Feature
- Reviewing Code
- Merging in General
- Pull Request Template
- Write Useful Commit Messages
- Avoid including files that are specific to your own environment.
- Avoid committing directly to
main
. - Perform all work in a feature branch.
- Rebase frequently to incorporate upstream changes.
- Use a pull request for code reviews.
- Delete your local and remote branches after merging.
git checkout main
git pull
git checkout -b <branch-name>
Prefix the branch name with something meaningful, for example:
users/username/description
users/username/workitem
feature/feature-name
feature/feature-area/feature-name
bugfix/description
hotfix/description
cleanup/description
chore/description
When you name your feature branches by convention using slashes, it provides a much nicer organization when viewing as directories as well as within any Git GUI apps.
git fetch origin
git rebase origin/main
Resolve conflicts. When feature is in a good state, stage the changes
git add --all
git status
git commit --verbose
Be sure to write a good commit message.
If you've created more than one commit, use a rebase to squash them into cohesive commits with good messages:
git rebase -i origin/main
git push origin <branch-name>
Submit a pull request. Ask for a code review.
Your team members will follow code review guidelines to avoid miscommunication. They make comments and ask questions directly on lines of code. When satisfied, they'll approve your pull request and leave a comment:
This is some excellent work, Ross. 👍
Once your PR has been approved, you are responsible for merging it.
To avoid a messy history, please rebase and squash low-value commits like "Fix whitespace" into one or a small number of valuable commit(s). Edit commit messages to reveal intent. Run tests.
git fetch origin
git rebase -i origin/main
This allows GitHub to automatically close your pull
request and mark it as merged when your commit(s) are pushed to main
. It also
makes it possible to find the pull request that brought in your changes.
git push --force origin <branch-name>
Force-pushing may not always be appropriate for every project, depending on
other factors like hooks or continuous integration. Pull Requests may also be
merged into main
(or whatever their target branch is) by simply
clicking the green "Merge Branch" button on the GitHub Pull Request page.
Note that GitHub offers three merge options: a merge commit, rebase and merge, and squash and merge. All are good for different situations. For example, merge commits are good for merging feature branches with many developers or that other feature branches depend on.
For short-lived, single-developer feature branches, we favor squashing to preserve a clean and easy-to-follow history.
Delete the remote branch.
git push origin --delete <branch-name>
Delete your local feature branch.
git branch --delete <branch-name>
Please add a Pull Request Template to your repo, to ensure that all pull requests follow our guide:
See our Standard Pull Request Template in this directory.
Please ensure that you follow commit message best practices:
- Separate subject from body with a blank line
- Limit the subject line to 50 characters
- Capitalize the first word of the subject line
- Do not end the subject line with a period
- Use the imperative mood in the subject line (e.g. "Fix the bug" not "Fixed the bug")
- Wrap the body at 72 characters
- Use the body to explain what and why vs. how
For example:
Present-tense summary under 50 characters
* More information about commit (under 72 characters).
* More information about commit (under 72 characters).
http://project.management-system.com/ticket/123
See our Standard Commit Message Template in this directory.
To use the template, save it to your local machines and add it to your .gitconfig
:
git config --global commit.template <.git-commit-template.txt file path>
For example, if you saved it to your home folder, try:
git config --global commit.template ~/.git-commit-template.txt