Functions and Classes in Python

Revisit Version Control and Git

Overview:

  • Teaching: 5 min
  • Exercises: 5 min

Questions

  • What is version control and when should you use it?
  • What programs can I use for version control?

Objectives

  • Know that version control can be used to keep track of changes to your work
  • Understand that used correctly version control helps you to understand what and why you did something in the past
  • Git can be used to easily back up your work remotely

Why Use Version Control ?

  • Have you ever been coding on a project that was working, made a change the broke it and weren't able to get back to a working state?

  • Have you wondered why you made a particular change to your code aboaut a year ago

  • Is all your analysis and the code only on your laptop which might blow up / get stolen / be left behind somewhere? If you did back it up how long ago was that, could you recreate all the work since then from memory?

  • In years gone by open source software was distributed as compressed tar archives. Nowadays it is common to point people to a git repository.

  • A repository enables us to collaborate with others.

  • Many tools now integrate with version controol tools, e.g. IDEs, Code Review tools, Continuous Integration / Continuous Deployment

  • You can use a service like Zenodo to register DOIs (citable references) for particular versions of your software

Final.doc (c)Jorge Cham http://phdcomics.com/

Exercises

Exercise 1

Using the Terminal in JupyterHub

start-terminal-jupyterhub.png

In [1]:
%%bash2
git
usage: git [--version] [--help] [-c name=value]
           [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
           [-p|--paginate|--no-pager] [--no-replace-objects] [--bare]
           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
           <command> [<args>]

The most commonly used git commands are:
   add        Add file contents to the index
   bisect     Find by binary search the change that introduced a bug
   branch     List, create, or delete branches
   checkout   Checkout a branch or paths to the working tree
   clone      Clone a repository into a new directory
   commit     Record changes to the repository
   diff       Show changes between commits, commit and working tree, etc
   fetch      Download objects and refs from another repository
   grep       Print lines matching a pattern
   init       Create an empty Git repository or reinitialize an existing one
   log        Show commit logs
   merge      Join two or more development histories together
   mv         Move or rename a file, a directory, or a symlink
   pull       Fetch from and merge with another repository or a local branch
   push       Update remote refs along with associated objects
   rebase     Forward-port local commits to the updated upstream head
   reset      Reset current HEAD to the specified state
   rm         Remove files from the working tree and from the index
   show       Show various types of objects
   status     Show the working tree status
   tag        Create, list, delete or verify a tag object signed with GPG

'git help -a' and 'git help -g' lists available subcommands and some
concept guides. See 'git help <command>' or 'git help <concept>'
to read about a specific subcommand or concept.
In [3]:
%%bash2
git --version
git version 1.8.3.1
In [ ]:
%%bash2
git clone https://github.com/githubtraining/example-basic.git

In order to manage the training material we will use the %%bash2 magic in code cells. You should ignore this line wherever you see it, and like the demonstrator enter the commands in the terminal window.

Key Points:

  • Version control is a valuable tool to keep track of your code, documents, even your data
  • git is becoming the standard tool for version control
  • We will use git on the command line but numerous GUI packages exist.
  • We will use Github for remotes but other free options include Bitbucket and Gitlab