{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "name = '2015-12-11-meeting-summary'\n", "title = 'Introducing Git'\n", "tags = 'git, github, version control'\n", "author = 'Denis Sergeev'" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": true }, "outputs": [], "source": [ "from nb_tools import connect_notebook_to_post\n", "from IPython.core.display import HTML\n", "\n", "html = connect_notebook_to_post(name, title, tags, author)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Today we talked about git and its functionality for managing code, text documents and other building blocks of our research." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We followed a very good tutorial created by [**Software Carpentry**](http://swcarpentry.github.io/git-novice/). There are hundreds of other resources available online, for example, [**Git Real**](http://gitreal.codeschool.com/)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Hence, this post is not trying to be yet another git tutorial. Instead, below is just a brief recap of what commands were covered during the meeting." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Setting Up Git" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Set up your name and email so that each time you contribute to a project your commit has an author" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`git config --global user.name \"Python UEA\"`" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`git config --global user.email \"python@uea.ac.uk\"`" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Creating a Repository" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create a new directory for a project" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`mkdir myproject`" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Go into the newly created directory" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`cd myproject`" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Make the directory a Git repository" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`git init`" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Check status of the repository" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`git status`" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Tracking Changes" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Add a Python script to the repo (make the file staged for commit)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`git add awesome_script.py`" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Commit changes with a meaningful message" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`git commit -m \"Add awesome script written in Python\"`" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Exploring History" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Commits history" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`git log`" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Comparing different versions of files" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "List all untracked changes in the repository" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`git diff`" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Differences with “head minus one”, i.e. previous, commit" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`git diff HEAD~1 awesome_script.py`" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Differences with a specific commit" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`git diff awesome_script.py`" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Ignoring Things" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create a .gitignore file and put '*.pyc' line in it telling git will to ignore all Python bytecode files" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`echo '*.pyc' >> .gitignore`" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Include .gitignore in the repository" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`git add .gitignore`" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`git commit -m \"Add .gitignore file\"`" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`git status`" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Remotes in GitHub" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`git remote add origin git@github.com:/.git`" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`git push -u origin master`" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Issue on Grace" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If you use git on [Grace](http://rscs.uea.ac.uk/high-performance-computing) and have tried `git push` to a GitHub repository, you have probably encountered the following error:" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`fatal: unable to access 'https://github.com/***/***/': error:0D0C50A1:asn1 encoding routines:ASN1_item_verify:unknown message digest algorithm`" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "One of the possible solutions here is to switch off SSL verification by adding the following line in your .bashrc file:" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`export GIT_SSL_NO_VERIFY=true`" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", " \n", "

This post was written as an IPython (Jupyter) notebook. You can view or download it using\n", " nbviewer.

\n", " " ], "text/plain": [ "" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "HTML(html)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.10" } }, "nbformat": 4, "nbformat_minor": 0 }