{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Git\n", "A distributed version control system. These are the main concepts of git:\n", "![git concepts](git_concepts.png)\n", "`git pull` is the same as a `git fetch` followed by a `git merge`." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "## Settings\n", "Before you do anything do the following:\n", "```\n", "$ git config --global user.name \"John Doe\"\n", "$ git config --global user.email johndoe@example.com\n", "$ git config --global color.ui true\n", "```\n", "\n", "To access gitlab you will need to setup a ssh-key for your account.\n", "1. You can create a SSH key (if you don’t already have one), this will create a public/private keypair:\n", "```\n", "$ ssh-keygen -t rsa -C \"\"\n", "```\n", "\n", "- Then you copy the entire content of the public key \n", "(Linux: ~/.ssh/id_rsa.pub, Windows: \\.ssh\\id_rsa.pub)\n", "```\n", "$ cat ~/.ssh/id_rsa.pub % This will print the content on the console\n", "```\n", "\n", "- On the gitlab website open \"Profile Settings\">\"SSH Keys\">\"Add SSH Key\".\n", "- Paste the key ino the key text area, you may freely chose a title before adding the key\n", "- You can test whether it everything is setup correctly using\n", "```\n", "$ ssh git@sully.informatik.uni-stuttgart.de\n", "```\n", "- It may take a several minutes before a new key is recognized " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Important commands\n", "\n", "- Clones the group of `` repository into the current folder creating a local copy\n", "```\n", "$ git clone git@sully.informatik.uni-stuttgart.de:ai_lecture/group_.git\n", "```\n", "\n", "- Fetchs commits from the remote repository and merges any change to the local repository. **Use this to get new exercise after they have been released**\n", "```\n", "$ git pull\n", "```\n", "\n", "- Pushs commits from your local repository to the remote repository. This may fail due to change at the remote, then you have to pull before you can push. **Use this to hand in your solution, remeber to commit your work before doing so**\n", "```\n", "$ git push\n", "```\n", "\n", "- Returns the status of the working directory vs the repository (e.g. changes present?, new files?, removed files?)\n", "```\n", "$ git status\n", "```\n", "\n", "- Adds all new files to the the staging area (or use the file name instead of the dot for a single file)\n", "```\n", "$ git add . \n", "```\n", "\n", "- Commit all changes to the local repository, with the message `Your commit message`\n", "```\n", "$ git commit -m \"Your commit message\"\n", "```\n", "\n", "- Removes a file from the staging area and working directory.\n", "```\n", "$ git rm [-r] \n", "```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##Demo - Solving e00_firststeps for group_0\n", "This demo shows the workflow for doing the exercises.\n", "\n", "1a) Frist you need to clone your repository to get a local repository, this is only required once.\n", "```\n", "stefan@arbeitstier ~/gki $ git clone git@sully.informatik.uni-stuttgart.de:ai_lecture/group_0.git\n", "Cloning into 'group_0'...\n", "remote: Counting objects: 9, done.\n", "remote: Compressing objects: 100% (7/7), done.\n", "remote: Total 9 (delta 0), reused 0 (delta 0)\n", "Receiving objects: 100% (9/9), done.\n", "Checking connectivity... done.\n", "\n", "stefan@arbeitstier ~/gki $ cd group_0\n", "```\n", "\n", "1b) If you all ready have cloned it, remember to update your local repository by pull from the remote.\n", "This will also download new exercises, after they have been published.\n", "```\n", "stefan@arbeitstier ~/gki/group_0 (master) $ git pull % get changes from the remote\n", "```\n", "\n", "2) Solve the given exercises, in this demo \"e00_firststeps\" is solved.\n", "\n", "3) In the following are the steps required to test and upload your solution.\n", "```\n", "stefan@arbeitstier ~/gki/group_0 (master) $ cd e00_firststeps % testing works only in the exercise folder \n", "\n", "stefan@arbeitstier ~/gki/group_0/e00_firststeps (master) $ run_tests.sh % Testing my solution\n", "....\n", "----------------------------------------------------------------------\n", "Ran 4 tests in 0.000s\n", "\n", "OK\n", "\n", "stefan@arbeitstier ~/gki/group_0/e00_firststeps (master) $ git status\n", "On branch master\n", "Your branch is up-to-date with 'origin/master'.\n", "Changes not staged for commit:\n", " (use \"git add ...\" to update what will be committed)\n", " (use \"git checkout -- ...\" to discard changes in working directory)\n", "\n", " modified: e00_firststeps.py\n", "\n", "no changes added to commit (use \"git add\" and/or \"git commit -a\")\n", "\n", "stefan@arbeitstier ~/gki/group_0/e00_firststeps (master) $ git add e00_firststeps.py\n", "\n", "stefan@arbeitstier ~/gki/group_0/e00_firststeps (master) $ git status\n", "On branch master\n", "Your branch is up-to-date with 'origin/master'.\n", "Changes to be committed:\n", " (use \"git reset HEAD ...\" to unstage)\n", "\n", " modified: e00_firststeps.py\n", "\n", "stefan@arbeitstier ~/gki/group_0/e00_firststeps (master) $ git commit -m \"Solved e00\"\n", "[master a635953] Solved e00\n", " 1 file changed, 4 insertions(+), 4 deletions(-)\n", "\n", "stefan@arbeitstier ~/gki/group_0/e00_firststeps (master) $ git status\n", "On branch master\n", "Your branch is ahead of 'origin/master' by 1 commit.\n", " (use \"git push\" to publish your local commits)\n", "nothing to commit, working directory clean\n", "\n", "stefan@arbeitstier ~/gki/group_0/e00_firststeps (master) $ git push\n", "To git@sully.informatik.uni-stuttgart.de:ai_lecture/group_0.git\n", " 85c98ec..a635953 master -> master\n", "```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Demo - Creating a local git repository\n", "This is the git demo form last year\n", "```\n", "stefan@arbeitstier ~ % cd tmp\n", "stefan@arbeitstier ~/tmp % mkdir git_demo\n", "stefan@arbeitstier ~/tmp % cd git_demo\n", "stefan@arbeitstier ~/tmp/git_demo % git init\n", "Initialized empty Git repository in /home/stefan/tmp/git_demo/.git/\n", "stefan@arbeitstier ~/tmp/git_demo (git)-[master] % echo \"Test\" > README\n", "stefan@arbeitstier ~/tmp/git_demo (git)-[master] % git status\n", "# On branch master\n", "#\n", "# Initial commit\n", "#\n", "# Untracked files:\n", "# (use \"git add ...\" to include in what will be committed)\n", "#\n", "# README\n", "nothing added to commit but untracked files present (use \"git add\" to track)\n", "stefan@arbeitstier ~/tmp/git_demo (git)-[master] % git add README\n", "stefan@arbeitstier ~/tmp/git_demo (git)-[master] % git status\n", "# On branch master\n", "#\n", "# Initial commit\n", "#\n", "# Changes to be committed:\n", "# (use \"git rm --cached ...\" to unstage)\n", "#\n", "# new file: README\n", "#\n", "stefan@arbeitstier ~/tmp/git_demo (git)-[master] % git commit\n", "[master (root-commit) 615d9f7] Add README.\n", " 1 file changed, 1 insertion(+)\n", " create mode 100644 README\n", "stefan@arbeitstier ~/tmp/git_demo (git)-[master] % git status\n", "# On branch master\n", "nothing to commit (working directory clean)\n", "```" ] } ], "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.8" } }, "nbformat": 4, "nbformat_minor": 0 }