DEV Community

Cover image for Reference Guide: Committing Changes
kymiddleton
kymiddleton

Posted on • Updated on

Reference Guide: Committing Changes

Welcome back for part three of my reference guide series.

  • Go here for Part One: Reference Guide: Common Commands for Terminal.
  • Go here for Part two Create a GitHub Repository

COMMITTING CHANGES
When building a new application, a best practice for web development is to code a few lines, test a few lines, then commit changes. The commit process is the equivalent of saving changes to a document by clicking the save icon.

To commit file changes start by entering the following commands in the terminal:

  • git status
    • Items that appear in red indicate the files and subsequent changes are not being tracked. These files need to be staged and submitted.

git status

  • git add –A
    • This command initiates changes being tracked and the A indicates all files. This also transitions the code to be staged.
  • git status
    • Repeating this command will show the files previously highlighted in red have switched to green indicating changes have been tracked, saved and ready to push to the repository.

git add

  • git commit –m “add comment description of changes made”
    • Staged code is now saved locally with a note to others about the code. Makes commit messages descriptive and meaningful.
  • git status
    • Repeat command to verify all changes have been staged and ready to push to the repository.
  • git push origin master
    • Pushing to the master branch is something that should be limited to the first commit of a project repository.
    • Repositories with multiple collaborators should always have the master branch protected with changes being pushed to a branch then pulled into the master by creating a pull request.

Up next: Committing changes with branches.

For the completed Reference Guide Series:

Discussion (0)