New Branch is a different version of the Git project. It contains commits from master but also has commits that master does not have.
1. Create a new branch
git branch <branch_name>
2. Switch to the new branch:
git checkout <branch_name>
Once you switch branch, be now able to make commits on the branch that have no impact on master
.
You can continue your workflow, while master
stays intact!
3. Switch back to master branch:
git checkout master
4. Merge changes into master branch:
git merge <branch_name>
5. Delete the new branch:
git branch -d <branch_name>
generalizations
Let's take a moment to review the main concepts and commands from the lesson before moving on.
- Git branching allows users to experiment with different versions of a project by checking out separate branches to work on.
The following commands are useful in the Git branch workflow.
git branch
: Lists all a Git project's branches.git branch branch_name
: Creates a new branch.git checkout branch_name
: Used to switch from one branch to another.git merge branch_name
: Used to join file changes from one branch to another.git branch -d branch_name
: Deletes the branch specified.