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
  • Notes
  • Commands
  1. Cookbook

Branches

Notes

  • A branch is a reference to an existing commit (not as intuitively thought as a chain of commits).

  • A branch diverges from another branch only if the referenced commit shares an ancestor with another commit.

Commands

  • Show branches

    • git branch --list, or simply git branch

    • git branch -r to list remote branches

    • git show-branch -a show a detailed list

    • git log --oneline --decorate --graph --all to show a visual diagram

  • Create a branch

    • git branch <branch-name>

  • Change to a branch, both are equivalent. Using switch is more unambiguous.

    • git checkout <branch-name>

    • git switch <branch-name>

  • Rename a branch

    • git branch -m <new-name> rename current branch

    • git branch -m <old-name> <new-name> other branch

  • Delete a local branch

    • git branch -d <branch-name> if fully merged

    • git branch -D <branch-name> if not fully merged, could result in data loss. Use with caution.

  • Delete a remote branch

    • git push origin --delete <branch-name>

PreviousUndoNextDiff

Last updated 1 year ago