clubmate.fi

A good[ish] website

Web development blog, loads of UI and JavaScript topics

Git: handy branching commands

Filed under: Webdev— Tagged with: branch, git

Here’s a little cheat sheet to help deal with branches.

Listing branches

List branches:

$ git brach

List remote branches:

$ git branch --remote # Or -r for short

List remote branches that are not tracked:

$ git ls-remote --heads <remote-name>

Making and editing branches

Make a new branch based on the active branch:

$ git branch <branch-name>

Rename a branch:

$ git branch -m <old-name> <new-name>

Rename the active branch:

$ git branch -m <new-name>

Deleting branches

Delete a branch in a safe manner:

$ git branch -d <branch-name>

Git docs on the -d flag:

Delete a branch. The branch must be fully merged in its upstream branch, or in HEAD if no upstream was set with

If a branch that is not merged is wanted to be deleted, use the capital D -D flag to force it:

$ git branch -D <branch-name>

Delete remote branch:

$ git branch -d -r origin/<branch-name>

Kernel.org has great git docs.

Comments would go here, but the commenting system isn’t ready yet, sorry. Tweet me @hiljaa if you want to make a correction etc.

  • © 2021 Antti Hiljá
  • About
  • Follow me in Twatter → @hiljaa
  • All rights reserved yadda yadda.
  • I can put just about anything here, no one reads the footer anyways.
  • console.log('Smash the patriarchy!')
  • I love u!