Reference Guide: Committing Changes with Branches
Tags: codenewbie, beginners, webdev, productivity
Published: 2018-12-15 14:52:31

---
cover_image: https://www.webretailer.com/lean-commerce/wp-content/uploads/2014/09/Colourful-baby-steps.jpg
title: Reference Guide: Committing Changes with Branches
published: true
description: A reference guide series for new web developers. 
tags: #codenewbie #beginners #webdev #productivity
---
When I first started working with branches I could never remember which branch I was on when it came time to commit changes.  My go-to command quickly became `git branch`.  

If you missed part of the series:
- [Part One:](https://dev.to/kymiddleton/reference-guide-common-commands-for-terminal-6no) Reference Guide: Common Commands for Terminal. 
- [Part two:](https://dev.to/kymiddleton/reference-guide-create-a-github-repository-30f8) Create a GitHub Repository
- [Part three:](https://dev.to/kymiddleton/reference-guide-committing-changes-43el) Committing Changes


**COMMITTING CHANGES WITH BRANCHES**
It’s best to think of the `master` branch as production.  Therefore, it’s best to never push to the master branch.  When using branches remember they run parallel to the master.  As soon as a new project is created get into the habit of creating a new branch before making file changes.  It’s also best to create a new branch for each design feature. 

**Branch commands:**
- `git branch`
    * Displays branches within current project including the master branch.

![git branch](https://thepracticaldev.s3.amazonaws.com/i/u3cbvm06ppcg2axhemwb.jpeg)

- `git checkout <branch name>`
    * Used to switch to a different branch. 

**Make a new branch:**
- `git checkout –b <name of new branch>`
    * `Checkout` is similar to the homepage of a website by indicating a switch from the homepage or `master` branch to an alternate page view or `branch`. 
    * `-b` initiates a new branch to be created. 

![git checkout b](https://thepracticaldev.s3.amazonaws.com/i/7ub81mpp6uya7i78y6qm.jpeg)

When code is ready to be committed to a branch use the following commands: 
- `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 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 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 <name of branch>`
    * Saved changes are pushed to the named branch. 


Up next: [Handling Merge Conflicts](https://dev.to/kymiddleton/reference-guide-merge-conflicts-6op)

For the completed Reference Guide Series: 
- [Part One:](https://dev.to/kymiddleton/reference-guide-common-commands-for-terminal-6no) Reference Guide: Common Commands for Terminal. 
- [Part two:](https://dev.to/kymiddleton/reference-guide-create-a-github-repository-30f8) Create a GitHub Repository
- [Part three:](https://dev.to/kymiddleton/reference-guide-committing-changes-43el) Committing Changes
- [Part four:](https://dev.to/kymiddleton/reference-guide-committing-changes-with-branches-2f8d) Committing Changes with Branches
-[Part five:]( https://dev.to/kymiddleton/reference-guide-merge-conflicts-6op) Merge Conflicts
- [Part six:](https://dev.to/kymiddleton/reference-guide-pull-requests-5an9) Pull Requests
- [Part seven:](https://dev.to/kymiddleton/reference-guide-conducting-a-code-review-k6m) Conducting a Code Review
-[Part eight:]( https://dev.to/kymiddleton/reference-guide-complete-and-merge-a-pull-request--12n4) Complete and Merge a Pull Request