Commit, branch and merge with Git

DevOps, Hands On20 minutesFreeWritten 14 November 2026By Cloud Hands On

In this task you'll record a change, try it on a branch and merge it.

Git records every change to a set of files as a commit, with who made it, when and why. A branch is a line of commits you can work on without touching main; merging brings the work back.

Small, frequent commits with clear messages make history useful: you can see exactly when something changed and undo it.

Example. A SS Kaiser developer fixes a typo in the checkout page on a branch called fix/checkout-typo, commits with the message 'Fix typo in checkout total label', and merges it into main after review.

Before you start

You need: Cloud Shell (Git is installed). Time: 20 minutes.

Where to look

  1. git init
  2. git add
  3. git commit
  4. git switch -c
  5. git merge

Steps

  1. Run git config --global user.name "Your Name" and the same with user.email.Every commit records this. Use the email your GitHub account knows.
  2. Make a folder and start a repository: mkdir shop && cd shop && git init -b main.
  3. Create a file (echo "<h1>SS Kaiser shop</h1>" > index.html), then git add index.html and git commit -m "Add home page".
  4. Make a branch: git switch -c feature/title, change the file, add and commit it.main hasn't changed: check with git log --oneline main.
  5. Go back and merge: git switch main, then git merge feature/title.git log --oneline --graph shows the history.

Commands

git init -b main
git add .
git commit -m "Describe the change"
git switch -c feature/x
git switch main
git merge feature/x
git log --oneline --graph

Watch out for

Cost
Free.
Security
Commits are permanent history: anything you commit, including a password, stays in it even if you delete the file later.
Common mistakes
Huge commits with messages like 'changes', and committing straight to main instead of a branch.

Clean up

Delete the practice folder: rm -rf ~/shop.

Words to know

Commit
A saved snapshot of changes, with a message.
Branch
A movable pointer to a line of commits.
Merge
Combining one branch's commits into another.

Tick off each step and track your progress in the guide.

Open this task in DevOps, Hands On

Keep going