3 Getting Started

3.1 Initialize a repository

  • git init inside the directory first_git_project.

  • ls -la shows the directory .git. This lets us know that git has been initialized in this directory.

3.2 Where git files are stored

  • leave everything in .git alone.

  • you can check project level config at cat .git/config.

  • DO NOT delete this directory. All the tracking is stored here.

  • other version control tools may store tracking in every folder.

    • not in git! everything is in .git.

3.3 First commit

  • create a file first_file.txt.

  • make git track this change.

  • First, git add . adds ALL changes in the current directory.

  • adding does not track changes (yet).

  • track changes using git commit -m "Initial commit". This commits all changes that were added.

Process:

  1. Make changes.

  2. Add changes.

  3. Commit changes with a message.

3.4 Write commit messages

How do we write good commit messages? Best practices:

  1. A short single-line summary (less than 50 characters)

  2. Optionally followed by a blank line and more complete description

  3. Still keep each line to less than 72 characters (for improved viewability)

  4. Write commite messages in present tense, not past tense

    • “fix for a bug” or “fixes a bug”, not “fixed a bug.

    • This is what’s inside the commit.

  5. Bullet points are usually asterisks or hyphens

  6. Can add “tracking numbers” from bugs or support requests

  7. Can develop shorthand for your organization

    • eg.: “[css, js]”, “bugfix:”, “#38405 -“

  8. Be clear and descriptive

    • bad: “fix typo”

    • good: “add missing hyphen in project section of HTML”

    • bad: “update login code”

    • good: “change user authentication to use blowfish”

    • bad: “updates member report, we should discuss if this is right next week” (extra information doesn’t have place in permanent commit log)

Example:
“ghi2394 - Fixes bug in admin logout

When an admin logged out of the admin area, they
could not long in to the members area …”

3.5 View the commit log

  • use git log to see commit log/history

  • commit unique_commit_ID

  • git help log to use other options

  • git log -n 5 limits number of commits to 5 most recent

  • git log --since=2020-01-01 all commits since jan 1st, 2019

  • git log --until=2021-01-01

  • git log --author="makto" part of the name suffices

  • grep stands for “globally search for regular expressions”

  • git log --grep="init" case sensitive on linux