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