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

Similar documents
CS 390 Software Engineering Lecture 5 More Git

Computer Science Design I Version Control with Git

Version Control with GIT

Git for Version Control

Version Control: Gitting Started

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

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

Version control with Git.

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

Introduction to distributed version control with git

Algorithm Engineering

A BASIC UNDERSTANDING OF VERSION CONTROL

Git Introduction CS 400. February 11, 2018

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

CS 390 Software Engineering Lecture 4 - Git

Version Control. Version Control

Software Development I

Introduction to Version Control with Git

Submitting your Work using GIT

Introduction to Git and Github

Version Control. Version Control

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

Version Control Systems

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

CSE 391 Lecture 9. Version control with Git

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

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

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

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

Git. Presenter: Haotao (Eric) Lai Contact:

Introduction to Git. Database Systems DataLab, CS, NTHU Spring, 2018

Fundamentals of Git 1

Chapter 5. Version Control: Git

Git tutorial. Katie Osterried C2SM. October 22, 2015

Software Project (Lecture 4): Git & Github

G E T T I N G S TA R T E D W I T H G I T

Lab 01 How to Survive & Introduction to Git. Web Programming DataLab, CS, NTHU

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

1. Git. Robert Snapp

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

Revision control. INF5750/ Lecture 2 (Part I)

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:

Object Oriented Programming. Week 1 Part 2 Git and egit

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

API RI. Application Programming Interface Reference Implementation. Policies and Procedures Discussion

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

Tutorial 2 GitHub Tutorial

Git Branching. Chapter What a Branch Is

Introduction to Version Control

GETTING STARTED WITH. Michael Lessard Senior Solutions Architect June 2017

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

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.

VCS VERSION CONTROL SYSTEMS

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

Visualizing Git Workflows. A visual guide to 539 workflows

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

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

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

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

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

GETTING TO KNOW GIT: PART II JUSTIN ELLIOTT PENN STATE UNIVERSITY

Version Control with Git

Git Magic: Versioning Files Like a Boss. Tommy MacWilliam

Git version control with Eclipse (EGit) Tutorial

From Commits to Collaboration: A Git Tutorial for Social Scientists

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

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

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

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

Git. Ľubomír Prda. IT4Innovations.

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

Git: Distributed Version Control

Git(Lab) Tutorial and Hands-On

Windows. Everywhere else

Git Workflows. Sylvain Bouveret, Grégory Mounié, Matthieu Moy

Git for Newbies. ComMouse Dongyue Studio

Online Remote Repositories

GIT FOR SYSTEM ADMINS JUSTIN ELLIOTT PENN STATE UNIVERSITY

Basic git. Interactive.

Improving Your Life With Git

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

AIS Grid School 2015

Source Code Management wih git

Version Control with GIT: an introduction


Laboratorio di Programmazione. Prof. Marco Bertini

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

Assumptions. GIT Commands. OS Commands

b. Developing multiple versions of a software project in parallel

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

Common Git Commands. Git Crash Course. Teon Banek April 7, Teon Banek (TakeLab) Common Git Commands TakeLab 1 / 18

Barry Grant

Revision control Advanced git

Intermediate Programming, Spring Misha Kazhdan

Revision Control and GIT

I m an egotistical bastard, and I name all my projects after myself. First Linux, now git. Linus Torvalds, creator of Linux and Git

FAQ Q: Where/in which branch do I create new code/modify existing code? A: Q: How do I commit new changes? A:

Lecture 4 More on Commits and Branches

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

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

Transcription:

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

GIT Overview GIT Basics Highlights: snapshot, the three states Working with the Private (Local) Repository Creating a repository and making changes to it Working with the Public (Remote) Repository Accessing protocols Fetching, pulling, and pushing GIT Branching GIT Working Flows 1

Recall what we have learned Decentralized Repository Model 2

GIT Basics History Developed by Linus Tornalds, the creator of Linux, in 2005. Keywords: performance, distributed, trust Installation http://git-scm.com Setting up git config --global user.name Jack Smith (specify your name) git config --global user.email jack@hotmail.com (specify email) git config --global core.editor emacs (specify the default editor) git help <verb> (get help) 3

GIT Highlights Snapshots, Not Differences Most version control systems store a set of files and the changes made to each file over time. GIT saves the state of your project: every time you commit, GIT records (i.e. takes a picture of) all the files and stores a reference to that snapshot. If files have not changed, GIT stores just a link to the previous identical file it already stored. 4

GIT Highlights 5

GIT Highlights 6

GIT Highlights The Three States Committed: the data is safely stored in your local database. Modified: you have changed the file but have not committed it to your database yet. Staged: you have marked a modified file in its current version to go into your next commit snapshot. The GIT directory: the object database for your project. The working directory: a single checkout of one version of the project that is ready to be modified. The staging area: a simple file that stores information about what will go into your next commit. 7

GIT Highlights 8

Working with the Private Repository Creating a local repository Initializing a repository from an existing directory Cloning a remote repository Making changes to the repository Tracking new files Staging modified files Committing changes checking the status Viewing the commit history Undoing changes 9

Creating a local repository Initializing a repository from an existing directory Go to the project s directory and type git init. This creates a new subdirectory named.git GIT directory. Cloning a remote repository: git clone [url] Creates a new directory Initializes a.git directory in the new directory. Pulls down all the data from the repository. Checks out a working copy of the latest version. Add the repository to your remote server list (named origin ). Automatically creates a master branch that tracks origin/master. 10

Making changes 11

Making changes Tracking new files The change will be automatically staged. git add README (to begin tracking the README file) Staging modified files After you change a file that was already tracked, you need to explicitly stage it into your next commit. git add benchmark (assuming that the benchmark file was tracked and modified) About git add: a multipurpose command To begin tracking new files To stage files To mark merge-conflicted files as resolved 12

Making changes Checking the status of working directory The git status command determines which files are in which state. 13

Making changes Committing changes Only commit the staged changes. git commit m The commit command records the snapshot you set up in your staging area. Viewing the commit history Use the git log command Many options are available, such as p, -2, etc. 14

Undoing changes Changing you last commit Overwrite the previous commit, and end up with a single commit. git commit --amend Unstaging a staged file Cancel the changes made to the staging area. git reset HEAD <file> E.g. git reset HEAD benchmarks Unmodifiying a modified file Cancel the working directory changes git checkout -- <file> E.g. git checkout -- benchmarks 15

Working with the Public Repository Protocols of accessing remotes Creating a repository on the server Managing remotes Adding remote repositories Listing remotes Inspecting a remote Removing and renaming remotes Fetching and pulling from remotes Pushing to remotes 16

Protocols of accessing remotes Local protocol: used when the remote repository is in another directory on disk. E.g. git clone /opt/git/project.git The SSH protocol: the most common transport protocol of GIT. The only network-based protocol that you can write to. GIT servers authenticate using SSH public keys. E.g. git ssh://user@server:project.git The GIT protocol The HTTP/S protocol 17

Creating a repository on a server Bare repository: a GIT repository that has no working directory. Bare repository is the contents of your project s.git subdirectory. This is your Git repository where all the data of your project snapshots are stored. To create a repository from an existing directory of files, simply run git init --bare in that directory. An SSH server and a bare repository are the only two things you need to collaborate with other people on a project. 18

Managing remotes Adding remote repositories git remote add [shortname] [url] E.g. git remote add pb git://github.com/paulboone/ticgit.git Listing remotes List remote servers that you have configured If you have cloned your repository, you should see at least origin the default name GIT gives to the server you cloned from. git remote v (the v option includes the URL that GIT stored for the shortname) 19

Managing remotes Inspecting a remote Shows more information about a particular remote, particularly about the branches. git remote show [remote-name] Removing and renaming remotes Rename the name of a reference git remote rename [old-name] [new-name] Remove a remote git remote rm [remote-name] 20

Fetching and Pulling from Remotes Fetching: git fetch [remote-name] Pulls down all the data from the remote project to your local repository. Get references to all the branches from that remote. Note: fetching does not make changes to your current working directory. Pulling: git pull Running git pull fetches data from the server, and automatically tries to merge it into the code you are currently working on. Can be seen as running git fetch followed by git merge, which will be introduced later. 21

Pushing to Remotes Pushing a local project to the remote (public) repository to share with other people The command: git push [remote] [branch] make your [branch] the new [branch] on the [remote] Requires write access to the remote server If your branch is already on the server, it will try to update it, if it is not, GIT will add it. May be rejected if someone else pushed to the server before you. 22

GIT Branching Branches in GIT Basic branching and merging Creating branches Switching between branches Basic Merging Remote branches Tracking branches 23

Branches in GIT When you commit in GIT, GIT stores a commit object that contains A pointer to the snapshot of the content you staged. The author and message metadata Zero or more pointers to the commit or commits that were the direct parents of this commit 0 parents: first commit 1 parent: a normal commit >1 parents: a commit resulting from a merge of two or more branches A branch in GIT is simply a lightweight movable pointer to one of these commit. Creating a new branch in GIT just creates a new pointer. 24

Branches in GIT 25

Branches in GIT 26

Basic Branching and Merging Branch management git branch [name-of-the-new-branch] (Create a branch) git branch (List all the current branches) git branch d [name-of-the-branch-to-delete] (Delete a branch) Switching between branches git checkout [name-of-the-branch] Creating a branch and switching to it at the same time git checkout b [name-of-the-branch] 27

Basic Branching and Merging To merge Branch A into Branch B Switch to Branch B: git checkout B Run the git merge command: git merge A GIT uses a three-way merging mechanism that identifies the best common ancestor. 28

Basic Branching and Merging As the result of merging, GIT creates a new snapshot and automatically creates a new commit that points to it. 29

Basic Branching and Merging Merge conflicts: the same part of the same file was changed differently in the two branches you are merging together. Again, merge conflicts have to be manually resolved. After you have resolved the conflicts, run git add on each conflicted file to mark it as resolved. 30

Remote branches Remote branches are references to the state of branches on your remote repositories. They take the form (remote)/(branch) E.g. origin/master Pushing a branch to the server. git push (remote) (branch) E.g. git push origin serverfix:adifferentname Merging a remote branch git merge origin/serverfix 31

Remote branches Tracking branches: checking out a local branch from a remote branch automatically creates what is called a tracking branch. git checkout b serverfix origin/serverfix Tracking branches are local branches that have a direct relationship to a remote branch. If you are on a tracking branch and type git push, GIT automatically knows which server and branch to push to. Similarly, running git pull while on one of these branches fetches all the remote references and then automatically merges in the corresponding branch. 32

GIT Working Flow Having several branches open at the same time, with each used for different stages of your development cycle. Centralized workflow All peers share the same public (remote) repository. Integration-Manager Workflow There are multiple remote repositories. Each developer has write access to their own public repository, and read access to everyone else s. This scenario often includes a canonical repository that represents the official project. 33

GIT Working Flow 34

Reference All the diagrams of this lecture are from the book Pro Git by Scott Chacon. 35