Skip to main content
Dan Rodney/4 min read

Branches: Create, Switch, Push, Merge, & Delete

Essential Git Commands

git status

What's changed, staged, and untracked — your most-used command.

git diff

See exactly what's different before staging.

git log

Inspect commit history with --oneline or --graph for visualization.

git reset

Undo staging or commits — careful with --hard.

Build Programming Foundations at Noble Desktop

Noble Desktop's Full-Stack Web Development Certificate teaches Git alongside the modern web stack — a must for any developer.

Learn to efficiently use Git branches to enhance collaborative workflows, manage multiple versions of code, and seamlessly integrate new features into the main code base.

Git Branches

Git lets you branch out from the original code base. This lets you more easily work with other developers, and gives you a lot of flexibility in your workflow.

Here’s an example of how Git branches are useful. Let’s say you need to work on a new feature for a website. You create a new branch and start working. You haven’t finished your new feature, but you get a request to make a rush change that needs to go live on the site today. You switch back to the master branch, make the change, and push it live. Then you can switch back to your new feature branch and finish your work. When you’re done, you merge the new feature branch into the master branch and both the new feature and rush change are kept!

Working on a Branch: Commit, Push, Pull, Etc.

Keep in mind that whenever you commit, push, pull, etc. you’re doing so on a branch. So make sure you’re on the correct branch you doing any Git commands.

See What Branch You’re on

The current branch is shown at the bottom left of the Visual Studio Code window (master is the default branch name).

Create a New Branch

  1. At the bottom left of the Visual Studio Code window click the current branch name (master is the default branch name).
  2. In panel that appears at the top of the window, choose + Create new branch.
  3. Type in a name for your new branch and hit Return (Mac) or Enter (Windows)

    You’re now ready to commit to this branch.

Switch to a Branch in Your Local Repo

  1. At the bottom left of the Visual Studio Code window click the current branch name (master is the default branch name).
  2. A panel will appear at the top of the window listing the branches. Choose the branch that you want to switch to.

Switch to a Branch in a Remote Repo

  1. To get the list of branches from GitHub, at the top right of Source Control panel click the More Actions button and go into Pull, Push and choose Fetch.
  2. At the bottom left of the window click the current branch name (master is the default branch name).
  3. A panel will appear at the top of the window listing the branches. The ones that start with origin/ are remote branches. Choose the branch that you want to switch to.

Fetch Versus Pull

Fetch downloads new data from the remote repo, but does not merge that into your files.

Pull downloads new data from the remote repo (using fetch), and merges it into your files.

Merge a Branch

  1. Switch to the branch that you want to merge another branch into (changes will be merged into this branch).

    Most commonly you’ll merge changes from another branch into the master branch, so you’ll typically switch to the master branch (at the bottom left of the window click the current branch name and choose the desired branch).

  2. In the Source Control panel make sure you don’t have any changes that need to be committed.
  3. Now you can merge another branch into the current branch. At the top right of Source Control panel click the More Actions button and from the menu choose Branch > Merge Branch.

  4. Select the branch you want to merge (into the current branch) and you’re done.

    NOTE: When you merge, there may be a conflict. Refer to How to Handle Merge Conflicts to learn what to do.

Delete a Local Branch

If you’re done with a branch and you don’t plan on using it again, you can delete it as follows:

  1. You can’t delete the current branch, so switch to different branch than you want to delete.
  2. At the top right of Source Control panel click the More Actions button and from the menu choose Branch > Delete Branch.

  3. Select the branch you want to delete.

    Confirm that you want to delete it, and you’re done.