EMAT10006: Further Computer Programming

Version control with git

Outline

Topics:

Git

Github

Example - CPython

The code for Python itself is kept under version control using git and hosted on github:

https://github.com/python/cpython

Start a git project

$ git clone https://github.com/myname/myrepo.git
$ cd myrepo
$ git status

Change the code

$ git status       # Check all clean
$ gedit README.md  # Make changes and save
$ git status       # Shows changed files
$ git diff         # Shows the changes
diff --git a/t.py b/t.py
index c5d61cf..fbcc63c 100644
--- a/t.py
+++ b/t.py
@@ -1,7 +1,7 @@
 def myfunction(x):
     y = 2
     z = 3
-    return y + z - x
+    return [y + z - x]

 # here is some code

Commit the changes

$ git status
$ git diff
$ git add README.md   # Tell git you want to commit
$ git commit -m "Add installation instructions in README"

Commit history

Commits represent the history of your work

initial commit -- A -- B -- C -- HEAD

Use git log to see the history (or look on github)

Committing

Push/pull

$ git status   # Always check clean first
$ git log      # What am I pushing?
$ git push

Get changes from github:

$ git pull

Push/pull

Send commits to and from github

push/pull
                               push
                           ----------->
          your computer                    github
                           <-----------
                               pull

Git

That's all