Version Control with GIT

Similar documents
Introduction to Git and Github

GIT. CS 490MT/5555, Spring 2017, Yongjie Zheng

Computer Science Design I Version Control with Git

GUIDE TO MAKE A REAL CONTRIBUTION TO AN OPEN SOURCE PROJECT 1. 1

Git Guide. Meher Krishna Patel. Created on : Octorber, 2017 Last updated : October, More documents are freely available at PythonDSP

Version control with Git.

GIT Princípy tvorby softvéru, FMFI UK Jana Kostičová,

Software Project (Lecture 4): Git & Github

Submitting your Work using GIT

CSE 391 Lecture 9. Version control with Git

CS 390 Software Engineering Lecture 4 - Git

Git for Version Control

CS 378: Autonomous Intelligent Robotics (FRI) Dr. Todd Hester

Git. Charles J. Geyer School of Statistics University of Minnesota. Stat 8054 Lecture Notes

git commit --amend git rebase <base> git reflog git checkout -b Create and check out a new branch named <branch>. Drop the -b

Tutorial: Getting Started with Git. Introduction to version control Benefits of using Git Basic commands Workflow

GETTING STARTED WITH. Michael Lessard Senior Solutions Architect June 2017

Git Introduction CS 400. February 11, 2018

VCS VERSION CONTROL SYSTEMS

LAB MANUAL GIT BY PRATIK JAIN. To start with git bash, we need to authenticate ourselves so that for every commit, git can use this information.

Using git to download and update BOUT++

1. Git. Robert Snapp

Index. Alias syntax, 31 Author and commit attributes, 334

Topics covered. Introduction to Git Git workflows Git key concepts Hands on session Branching models. Git 2

Git. Presenter: Haotao (Eric) Lai Contact:

Algorithm Engineering

Fundamentals of Git 1

Revision control. INF5750/ Lecture 2 (Part I)

A quick (and maybe practical) guide to Git and version control. By Jay Johnson

About SJTUG. SJTU *nix User Group SJTU Joyful Techie User Group

Outline. Version Control System (VCS) basics Git terminology & concepts Basic Git commands Branches in Git Git over the network (time permitting)

Chapter 5. Version Control: Git

Version Control: Gitting Started

Outline. Introduction to Version Control Systems Origins of Git Git terminology & concepts Basic Git commands Branches in Git Git over the network

What is version control? (discuss) Who has used version control? Favorite VCS? Uses of version control (read)

Software Revision Control for MASS. Git Installation / Configuration / Use


GIT FOR SYSTEM ADMINS JUSTIN ELLIOTT PENN STATE UNIVERSITY

Outline. Introduction to Version Control Systems Origins of Git Git terminology & concepts Basic Git commands Branches in Git Git over the network

Version Control with Git

EECS 470 Lab 4. Version Control System. Friday, 31 st January, 2014

John DeDourek Professor Emeritus Faculty of Computer Science University of New Brunswick GIT

Introduction to distributed version control with git

Git better. Collaborative project management using Git and GitHub. Matteo Sostero March 13, Sant Anna School of Advanced Studies

CS 390 Software Engineering Lecture 5 More Git

A BASIC UNDERSTANDING OF VERSION CONTROL

1/20/13 Git tutorial. Git tutorial. Mike Nolta. file:///users/nolta/github/reveal.js/git.html?print-paper#/ 1/31

Git. CSCI 5828: Foundations of Software Engineering Lecture 02a 08/27/2015

GIT. A free and open source distributed version control system. User Guide. January, Department of Computer Science and Engineering

Version Control Systems

Software Development I

Git tutorial. Katie Osterried C2SM. October 22, 2015

Introduction to Version Control

Source Code Management wih git

What is Git? What is Git? Version Control. Barry Grant

! #Running this command from the top directory of your project will add all your changes."! $ git add."

Tutorial 2 GitHub Tutorial

Barry Grant

Lecture 6 Remotes. Sign in on the attendance sheet!

Introduction to Version Control with Git and GitHub

Version Control. Second level Third level Fourth level Fifth level. - Software Development Project. January 17, 2018

Improving Your Life With Git

Introduction to GIT. Jordi Blasco 14 Oct 2011

Git. Ľubomír Prda. IT4Innovations.

Git, the magical version control

From Commits to Collaboration: A Git Tutorial for Social Scientists

Lab Exercise Git: A distributed version control system

Introduction to Version Control with Git

Revision Control and GIT

License. Introduction to Version Control with Git. Local Version Control Systems. Why Use Version Control?

git Version: 2.0b Merge combines trees, and checks out the result Pull does a fetch, then a merge If you only can remember one command:

Introduction to Supercomputing

2 Initialize a git repository on your machine, add a README file, commit and push

So#ware(Project. Lecture'4. Wouter'Swierstra. So#ware(project( (Lecture(4 1

Git version control with Eclipse (EGit) Tutorial

What is git? Distributed Version Control System (VCS); Created by Linus Torvalds, to help with Linux development;

A Brief Introduction to Git. Sylverie Herbert (based on slides by Hautahi Kingi)

Advanced Operating Systems Control Versioning with GIT. Giuseppe Massari

Assumptions. GIT Commands. OS Commands

Reproducibility with git and rmarkdown

Version Control. Version Control

How to version control like a pro: a roadmap to your reproducible & collaborative research

CS314 Software Engineering Configuration Management

Git. all meaningful operations can be expressed in terms of the rebase command. -Linus Torvalds, 2015

Agenda. Several projects are using GIT Developer(s) Junio Hamano, Linus Torvalds. Qt Stable release (January 31, 2011)

Versioning with git. Moritz August Git/Bash/Python-Course for MPE. Moritz August Versioning with Git

CESSDA Expert Seminar 13 & 14 September 2016 Prague, Czech Republic

[Software Development] Development Tools. Davide Balzarotti. Eurecom Sophia Antipolis, France

AIS Grid School 2015

Outline The three W s Overview of gits structure Using git Final stuff. Git. A fast distributed revision control system

Version control with git and Rstudio. Remko Duursma

Software Engineering

Git. A fast distributed revision control system. Nils Moschüring PhD Student (LMU)

Git AN INTRODUCTION. Introduction to Git as a version control system: concepts, main features and practical aspects.

Github Webinar Documentation

Laboratorio di Programmazione. Prof. Marco Bertini

Θερινό Σχολείο, Ιουλίου git. Αχιλλέας Πιπινέλης. Μονάδα Αριστείας ΕΛ/ΛΑΚ ΤΕΙ Αθήνας

Gitting things done. Hands-on introduction to git niceties. Jan Urbański Ducksboard

Push up your code next generation version control with (E)Git

E, F. deleteall command, 352 directory structure, 350 export_data method, 353 inline_data method, 353 print_export method, 351 target directory, 351

Transcription:

Version Control with GIT Benjamin Roth CIS LMU München Benjamin Roth (CIS LMU München) Version Control with GIT 1 / 30

Version Control Version control [...] is the management of changes to documents, computer programs, large web sites, and other collections of information. (Wikipedia) Track changes over time. ( What was the reason we changed this? ) Option to undo and redo. Collaboration. Not just for managing source code, websites etc: also for writing theses, reports, archiving results from experiments,... This class: basic git concepts using the command line. Benjamin Roth (CIS LMU München) Version Control with GIT 2 / 30

Git Developed in 2005 by Linus Torvalds and other Linux kernel developers. Free software under GNU GPL. De facto standard for version control today. Distributed: Every Git working directory is a full-fledged repository complete history and full version-tracking capabilities independent of network access or a central server. Rapid branching and merging: A change will be merged more often than it is written. Benjamin Roth (CIS LMU München) Version Control with GIT 3 / 30

Git Underlying Ideas Git thinks of data like a set of snapshots of a miniature filesystem. With every commit, Git takes a snapshot of your files and stores a reference to that snapshot. Efficiency: If files have not changed, Git stores just a link to the previous identical file it has already stored. Benjamin Roth (CIS LMU München) Version Control with GIT 4 / 30

Git Underlying Ideas Most operations in Git only need local files and resources to operate. Check-sums: Everything is referred to by a checksum. SHA-1 hashing: 24b9da6552252987aa493b52f8696cd6d3b00373 Git generally only adds data: hard to do anything that is not undoable (e.g. permanently erase data). Benjamin Roth (CIS LMU München) Version Control with GIT 5 / 30

Git: States Files can be in the following states: unmodified / committed: data is safely stored in your local database. modified: file changed but not committed to database yet. staged: modified file is marked to go into your next commit. (untracked: file not managed by git) Benjamin Roth (CIS LMU München) Version Control with GIT 6 / 30

Recording Changes to the Repo Tracked files: Files that were in the last snapshot...... and newly added files. Can be unmodified, modified, or staged. Untracked files: Anything else After first clone: All files will be tracked and unmodified. Adding untracked file: file will be staged. etc. Benjamin Roth (CIS LMU München) Version Control with GIT 7 / 30

Git Places and Directories Working directory: single checkout of one version of the project. Placed on disk to be used and modified. Staging area: File (in.git directory) storing what will go into the next commit..git directory: Contains object database with complete project history and meta-data. Benjamin Roth (CIS LMU München) Version Control with GIT 8 / 30

Basic Git Workflow 1 Modify files in working directory 2 Stage the files Add snapshot to staging area 3 Do a commit Stores snapshot of staging area permanently in repository. Benjamin Roth (CIS LMU München) Version Control with GIT 9 / 30

Configuring Git Setting up user name and email: git config --global user.name "John Doe" git config --global user.email johndoe@example.com Setting up different than default editor: git config --global core.editor emacs Getting help: git help config git-scm.com Benjamin Roth (CIS LMU München) Version Control with GIT 10 / 30

Setting up SSH for Git It can be convenient to connect with SSH to hosting services like GitHub and Bitbucket. No need to enter password all the time. To access a remote over SSH: Public ssh key (of your computer) is shared with server. Your computer can hence verify itself (using the corresponding private key). Just upload your public key (~/.ssh/id_rsa.pub) to the service. Benjamin Roth (CIS LMU München) Version Control with GIT 11 / 30

Using Git with a Server and SSH Check wether you already have a key pair: $ cat ~/.ssh/id_rsa.pub ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAklOUpkDHrfHY17SbrmTIp GPl+nafzlHDTYW7hdI4yZ5ew18JH4JW9jbhUFrviQzM7X88XypNDvjYNb mz+aw4ozpntpi89zpmvmluayrd2ce86z/il8b+gw3r3+1nkatmikjn2so NrRFi9wrf+M7Q== beroth@mylaptop.local If not, create it: $ ssh-keygen Copy-paste public key to Git hosting service (Github...), which will store it as an authorized key. Benjamin Roth (CIS LMU München) Version Control with GIT 12 / 30

Getting a Git Repository Either take an existing directory and import it into Git or clone an existing git repository. Importing directory and commit: git init git add *.c git add LICENSE git commit -m initial project version Getting a copy of an existing Git repository: With https: git clone https://github.com/username/projectname.git With ssh: git clone git@github.com:username/projectname.git Benjamin Roth (CIS LMU München) Version Control with GIT 13 / 30

Checking the Status of Files After clone: Clean working directory, there are no tracked and modified files. $ git status nothing to commit, working directory clean After creation of a new (untracked) file: $ echo My Project > README $ git status Untracked files: README Benjamin Roth (CIS LMU München) Version Control with GIT 14 / 30

Staging files: git add git add Start tracking a file: git add README If a file is modified after staging it will be listed twice: Once as staged: exactly as it was at the time of git add Once as modified: with the new modifications Benjamin Roth (CIS LMU München) Version Control with GIT 15 / 30

.gitignore Ignore a class of files do not add do not show as untracked e.g. binaries, compiled code....gitignore file: # no.a files *.a # ignore the TODO file in the current directory /TODO # ignore any build/ (sub)directory build/ Benjamin Roth (CIS LMU München) Version Control with GIT 16 / 30

Committing Changes git commit Only already staged changes will go into a commit: Changes done after git add will be ignored. git commit Will launch default editor: write a meaningful commit message! $ git commit -m "Story 182: Fix benchmarks for speed" [master 463dc4f] Story 182: Fix benchmarks for speed 2 files changed, 2 insertions(+) create mode 100644 README Benjamin Roth (CIS LMU München) Version Control with GIT 17 / 30

Add and Commit at the same Time git commit -a Skip staging area (-a flag): automatically stage (add) every file that is already tracked, and commit. git commit -a -m added new benchmarks Benjamin Roth (CIS LMU München) Version Control with GIT 18 / 30

Removing and moving files Files are never deleted from history entirely. Remove file from working directory and stage its removal (usual case): git rm README.txt Commit after that to make change permanent. Remove file from tracked files (but keep in working directory, e.g. if you forgot to add to.gitignore): git rm --cached README.txt Rename / move file: git mv README.md README Equivalent to: mv README.md README git rm README.md git add README Benjamin Roth (CIS LMU München) Version Control with GIT 19 / 30

Git diff Detailed overview of changes in file content, line-by-line (instead of file-by-file). git diff What have you changed but not yet staged? git diff --staged What have you staged that you are about to commit? git diff git diff --staged Benjamin Roth (CIS LMU München) Version Control with GIT 20 / 30

Git diff: Example git diff git diff --staged Stage the README file (created previously): $ git add README Add to the file: $ echo More text. >> README Compare new changes to staged version: $ git diff @@ -1 +1,2 @@ My project +More text. Benjamin Roth (CIS LMU München) Version Control with GIT 21 / 30

Viewing the Commit History: git log $ git log commit ca82a6dff817ec66f44342007202690a93763949 Author: Scott Chacon <schacon@gee-mail.com> Date: Mon Mar 17 21:52:11 2008-0700 changed the version number commit 085bb3bcb608e1e8451d4b2432f8ecbe6306e7e7 Author: Scott Chacon <schacon@gee-mail.com> Date: Sat Mar 15 16:40:33 2008-0700 removed unnecessary test commit a11bef06a3f659402fe7563abf99ad00de2209e6 Author: Scott Chacon <schacon@gee-mail.com> Date: Sat Mar 15 10:31:28 2008-0700 Benjamin Roth (CIS LMU München) Version Control with GIT 22 / 30

Viewing the Commit History: Options Show differences for each commit: git log -p Show last two commits only: git log -2 Show overview statistics: git log --stat Only hashes and commit messages: git log --pretty=oneline Only last two weeks: git log --since=2.weeks Many more options and combinations: $ git log --pretty="%h - %s" --author=beroth \ --since="2015-10-01" --before="2015-11-01" 5610e3b - Fix testcase failure when extended attributes ar acd3b9e - Enhance hold_lock_file_for_{update,append}() API f563754 - demonstrate breakage of detached checkout with s Benjamin Roth (CIS LMU München) Version Control with GIT 23 / 30

Undoing Things You already committed, but forgot to add a file, and/or want to amend the commit message: $ git commit -m initial commit $ git add forgotten_file $ git commit --amend You want to unstage a file that you have just staged: $ git add * $ git reset HEAD README.txt Unmodifying a file. You want to revert back to the version of the file that was last committed: git checkout -- CONTRIBUTING.md CAREFUL: All uncommitted modifications are lost irrecoverably! Benjamin Roth (CIS LMU München) Version Control with GIT 24 / 30

Remote Repositories Several remote repositories possible: Pushing and pulling from them vital for collaboration. If project was initially cloned, one remote repository already exists called origin: $ git clone https://github.com/beroth/ticgit $ git remote -v origin https://github.com/beroth/ticgit (fetch) origin https://github.com/beroth/ticgit (push) Benjamin Roth (CIS LMU München) Version Control with GIT 25 / 30

Remote Repositories You can add more remote repositories: $ git remote add mynewremote https://github.com/schacon/ticgit Fetch all the information from mynewremote: $ git fetch mynewremote * [new branch] master -> mynewremote/master * [new branch] ticgit -> mynewremote/ticgit The local project now contains a branch mynewremote/master that can be merged with the local master branch (more on branching later). Benjamin Roth (CIS LMU München) Version Control with GIT 26 / 30

git pull and git push git pull: fetch and merge All staged changes must be committed before merge can happen. git push: push your changes to remote If the remote had changed in the meantime, you need to pull (and merge) again. One can specify the remote and branch, if defaults (e.g. origin and master) are not appropriate. git pull <remotename> <branchname> git push <remotename> <branchname> show information about remote repository: git remote show Benjamin Roth (CIS LMU München) Version Control with GIT 27 / 30

A Typical Workflow 1 Get current project state from remote Initially: Clone project. git clone git@github.com:username/projectname.git Later: Fetch and merge changes from remote. Possibly resolve conflicts. git pull 2 Make changes Add a File. git add CHANGES.txt Edit a File. vi README.txt 3 Add and merge the changes locally. git commit -a -m "Summary of changes." 4 Fetch and merge changes from remote. Possibly resolve conflicts. git pull 5 Push changes to remote. git push Benjamin Roth (CIS LMU München) Version Control with GIT 28 / 30

Next Lecture Branches Merging Resolving conflicts GitHub Pull requests Benjamin Roth (CIS LMU München) Version Control with GIT 29 / 30

Questions? Benjamin Roth (CIS LMU München) Version Control with GIT 30 / 30