How to Switch Branches and Commit Changes in Git
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 switchto 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 statusto see changes that need to be staged or committed. - Staging Changes: Stage files with
git addso they’re ready to be committed. - Committing Updates: Save your work with
git commitand include a message describing your changes.
Full Git Workflow Demonstrated
- Switch Back and Forth Between Branches
git switch maingit switch your-feature-branch
- Edit Files
- Make the code or documentation changes you need.
- Check the Working Directory
git statusshows which files have changed and which are staged for commit.
- Stage Your Changes
git add <filename>stages your changes for the next commit.
- 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.