Git - Part 5: Branching
Create and checkout a new branch
git checkout -b feature-branch
Checkout existing branch (eg. master)
git checkout master
List all branches
git show-branch --list
Merge changes from feature branch
git merge feature-branch
Delete feature branch
git branch -d feature-branch
Exercise
- Create new file index.html and add some content
touch index.html
- Add index.html to the staging area and commit to master branch
git add index.html
git commit -m "Initial commit"
- Create new Git branch called 'feature-branch'
git checkout -b feature-branch
- Create file feature.html and add some content
touch feature.html
- Add and Commit all to this branch with message "Work on branch"
git add --all
git commit -m "Work on branch"
- Checout master branch
git checkout master
- Merge changes from feature-branch
git merge feature-branch
- Delete feature-branch
git branch -d feature-branch
- Check branch list (see: only master branch)
git show-branch --list
- Check git log (see: both commits)
git log