Skip to content
This repository has been archived by the owner on May 29, 2022. It is now read-only.

How to Commit

Bryan Masamitsu Parsons edited this page Sep 25, 2018 · 1 revision

HOWTO Use Git Commit

Simple Recipe:

  1. Make changes to one of more files: echo "Hello World" > README.txt
  2. Stage the changes: $ git add README.txt
  3. Commit the changes: $ git commit -m "Created new README.txt file"

Detailed Recipe:

  1. Always check what branch you are on before you commit
    • git branch -av
    • git checkout my_branch
  2. It's usually a really good idea to pull and merge updates for the branch you are on before you try to commit to it.
    • git fetch --all
    • git merge origin/my_branch my_branch
  3. When creating a new source file, or modifying an existing file, use git add to "stage" the change:
    • git add my_source_file.py
  4. Use git commit to create a way-point to which you can revert, or when your changes are finalized.
    • Option A: git commit my_source_file.py -m "Fixed a bug"
    • Option B: git commit my_source_file.py
  5. Fetch/pull updates to the branch you are working on before creating a new commit.
    • This allows for what is called a "fast forward" merge, and prevents a lot of extra merging.
  6. Write useful commit messages
    • Think of git commit messages as being part of a large log that can be searched later.
    • git log output can be piped to grep and other GNU utilities.
    • the better the format and keywords included in the commit messages, the more useful the git log output becomes.
  7. Suggestions for making nice commit messages that make git log more useful:
    • Format the log message so that it is easier to read and search later
    • explicitly list all affected files, classes, and methods in the commit message.
    • If possible, keep each line below 60 characters so they don't wrap
    • First line should be broadly descriptive, additional lines should include detail
    • Place two line returns after the first line so that the display in git log is not made impossibly noisy.