Git, Commit Messages & Pull Request Guidelines

Commit often & Push less

Commit Messages Guidelines

Always include the issue number in your commit message. Ex: "PRJ-104: Moved install profile to be under /profiles rather than /profiles/custom." Optionally include additional information in your commit message if your commit makes multiple changes to the codebase. Example: PRJ-104: Moved install profile to be under /profiles rather than /profiles/custom. Added the module security_review Added new install profile configuration option "feature-set"

Pull Request Guidelines

Always include a link to the issue in the PR comments Always review your PR for merge conflicts and fix those. Assign PR Reviewers to Shawn Smiley when it's ready for review (should happen by default). Send a slack message to Shawn Smiley when your PR is ready for review.

Cleaning up your Git repo

git fetch -p origin     prune your local "cache" of remote branches firs
git branch -D <branch name>    Deleting a local branch 
git push origin --delete <branch name>    push delete changes back up remote

Common git commands

git command    definition
git remote show origin     shows the origin of the git repo. 
git fetch     updates your remote-tracking branches
git pull    pulls remote changes
git add -p    add each change individually to a single commit
git rebase --interactive HEAD~2    merge your commits together
git clean -fd    remove untracked files and directories
git stash    save and remove local changes but do not commit them
git stash pop    return saved changes
git fetch

Git add -p lets you add your commits in small batches. By committing one change at a time, you can exclude changes that do not pertain to your commit message. This is helpful when other developers are reviewing your commit messages. Important to note that git add -p will only add changes to files, not add new files. You will still have to use git add for new files. git add -p.

When you use git add -p you will see the options Stage this hunk [y,n,q,a,d,/,e,?]? These options in more detail.

y -    stage this hunk
n -    do not stage this hunk
q -    quit; do not stage this hunk or any of the remaining ones
a -    stage this hunk and all later hunks in the file
d -    do not stage this hunk or any of the later hunks in the file
/ -    search for a hunk matching the given regex
j -    leave this hunk undecided, see next undecided hunk
J -    do not stage this hunk or any of the later hunks in the file
k -    leave this hunk undecided, see next undecided hunk
s -    leave this hunk undecided, see next hunk
e -    manually edit the current hunk
? -    print help

Pulling a Forked PR locally for code review

  • $ git fetch upstream pull/[pull id]/head:[branch name]

  • $ git fetch upstream

  • $ git rebase upstream/master

  • $ git push git@github.com:[user]/cgov-digital-platform [local_branch_name]:[remote_branch_name]

Last updated

Was this helpful?