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
  1. Basic Operations

Extend a Branch

Branches are comprised of commits. Any new commit is made at the tip of a branch, causing the branch to grow.

Now let's make a commit in the new branch:

  • A new file is created with import this as the content.

  • The file is staged and commited

λ echo import this > newfile.py

λ cat newfile.py
import this

λ git commit -am "Added new file"
On branch new
Untracked files:
  (use "git add <file>..." to include in what will be committed)
        newfile.py
nothing added to commit but untracked files present (use "git add" to track)

λ git commit --am "Added new file"
error: pathspec 'Added new file' did not match any file(s) known to git

λ git add newfile.py

λ git commit -m "Added new file"
[new e84601c] Added new file
 1 file changed, 1 insertion(+)
 create mode 100644 newfile.py

If we look at the commit history now, you will see HEAD is pointing to new and it's one commit ahead of master.

λ git log --oneline
e84601c (HEAD -> new) Added new file
a37231a (master) Revert "Added another file"
35ac407 Added another file
ee7ebbd Print out the std dev
b1e55d3 Print out the mean
c96c526 First commit

PreviousMake a BranchNextFast-forward merge

Last updated 1 year ago