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

  1. Create new file index.html and add some content
    touch index.html
  2. Add index.html to the staging area and commit to master branch
    git add index.html
    git commit -m "Initial commit"
  3. Create new Git branch called 'feature-branch'
    git checkout -b feature-branch
  4. Create file feature.html and add some content
    touch feature.html
  5. Add and Commit all to this branch with message "Work on branch"
    git add --all
    git commit -m "Work on branch"
  6. Checout master branch
    git checkout master
  7. Merge changes from feature-branch
    git merge feature-branch
  8. Delete feature-branch
    git branch -d feature-branch
  9. Check branch list (see: only master branch)
    git show-branch --list
  10. Check git log (see: both commits)
    git log