This beginner-friendly GitHub video teaches the basics of switching branches and committing changes in git, with guidance from the GitHub team.

How to Switch Branches and Commit Changes in Git

In this video, the GitHub team demonstrates essential git branch management skills:

  • Switching Branches: Learn how to use git switch to move between branches, including returning to your main branch and working with feature branches for isolated development.
  • Editing Files: Make edits in your chosen branch.
  • Status Checks: Use git status to see changes that need to be staged or committed.
  • Staging Changes: Stage files with git add so they’re ready to be committed.
  • Committing Updates: Save your work with git commit and include a message describing your changes.

Full Git Workflow Demonstrated

  1. Switch Back and Forth Between Branches
    • git switch main
    • git switch your-feature-branch
  2. Edit Files
    • Make the code or documentation changes you need.
  3. Check the Working Directory
    • git status shows which files have changed and which are staged for commit.
  4. Stage Your Changes
    • git add <filename> stages your changes for the next commit.
  5. Commit Your Work
    • git commit -m 'Describe your changes' records your edits in git history.

This tutorial is ideal for new developers starting with git and GitHub, illustrating a smooth workflow for making and recording changes in a project repository.

Learn More