Git and SSH

Create a branch and switch to it

Start a side path for a new feature or fix, so the main version stays safe while you work.

Fill these in once
  1. Create the branch and switch to it
    Terminal
    git switch -c fix-login-button
  2. Share it on GitHub
    Terminal
    git push -u origin fix-login-button

    Only needed when you want others to see it. Run it after your first commit.

Check it worked

  1. List your branches
    Terminal
    git branch

    The one with a * is the branch you're on.

Undo it
  1. Go back to main
    Terminal
    git switch main
  2. Delete the branch
    Terminal
    git branch -d fix-login-button

    Git refuses if the branch has work that isn't merged yet. Use -D to delete it anyway.

  1. Create the branch and switch to it
    Terminal · Ubuntu / Debian
    git switch -c fix-login-button
  2. Share it on GitHub
    Terminal · Ubuntu / Debian
    git push -u origin fix-login-button

    Only needed when you want others to see it. Run it after your first commit.

Check it worked

  1. List your branches
    Terminal · Ubuntu / Debian
    git branch

    The one with a * is the branch you're on.

Undo it
  1. Go back to main
    Terminal · Ubuntu / Debian
    git switch main
  2. Delete the branch
    Terminal · Ubuntu / Debian
    git branch -d fix-login-button

    Git refuses if the branch has work that isn't merged yet. Use -D to delete it anyway.

  1. Create the branch and switch to it
    PowerShell
    git switch -c fix-login-button
  2. Share it on GitHub
    PowerShell
    git push -u origin fix-login-button

    Only needed when you want others to see it. Run it after your first commit.

Check it worked

  1. List your branches
    PowerShell
    git branch

    The one with a * is the branch you're on.

Undo it
  1. Go back to main
    PowerShell
    git switch main
  2. Delete the branch
    PowerShell
    git branch -d fix-login-button

    Git refuses if the branch has work that isn't merged yet. Use -D to delete it anyway.

New to Branch? I explain it in plain English on Layman Terms.