Essential Git for Scientists
  • Introduction
  • Basic Concepts
    • Version Control
    • Git
    • Repo
    • Commits
    • Branches
    • Remotes
    • GitHub
    • De-centralisation
    • Summary
  • Basic Operations
    • Install Git
    • Create a Repo
    • Make a Commit
    • Inspect a Previous Commit
    • Revert a Change
    • Make a Branch
    • Extend a Branch
    • Fast-forward merge
    • Resolve conflicts
  • Intermediate Concepts
    • Commits
    • Three Trees
    • Rebase
    • Fetch
    • Pull
    • Push
  • Advanced Concepts
    • Reset
    • Interactive rebase
    • Formatted patches
    • Blame
    • Stash
    • Log filter
  • Cookbook
    • Undo
    • Branches
    • Diff
    • Stash
    • Merge
    • Hooks
    • Squashing
    • Rebase
    • Interactive Rebase
    • LFS
    • Submodules
    • Remote
    • Force push
    • Identify merged branches
    • Formated patches
    • Apply patches
    • Interactive rebase
    • Squash commits
    • Pull rebase
    • Log
    • Blame
    • Biset
    • Reset
  • Exercise
    • Exercise 1
    • Exercise 2
Powered by GitBook
On this page
  • View current branch
  • Create a new branch
  1. Basic Operations

Make a Branch

Every commit belongs to at least one branch. The default branch is typically named master or main.

View current branch

To view which branch you're current at, use git branch:

λ git branch
* master

This tells that I'm currently on the master branch.

Create a new branch

You can do this in two steps:

  • Create a branch: git branch <name>

  • Change to that branch: git checkout <name>

Or do it in just one step: creating then changing to that branch: git checkout -b <name>.

λ git checkout -b new
Switched to a new branch 'new'

λ git branch
  master
* new

Here I create a branch called new. When calling git branch again it shows I'm on branch new.

PreviousRevert a ChangeNextExtend a Branch

Last updated 1 year ago