Git Basics. Christopher Simpkins chris.simpkins@gatech.edu. Chris Simpkins (Georgia Tech) CS 2340 Objects and Design CS 1331 1 / 22



Similar documents
Version Control using Git and Github. Joseph Rivera

Version Control with. Ben Morgan

Introduction to Git. Markus Kötter Notes. Leinelab Workshop July 28, 2015

Version Control with Git. Kate Hedstrom ARSC, UAF

Version Control with Git. Linux Users Group UT Arlington. Rohit Rawat

Version Control with Svn, Git and git-svn. Kate Hedstrom ARSC, UAF

FEEG Applied Programming 3 - Version Control and Git II

Using Git for Project Management with µvision

Version Control. Version Control

Lab Exercise Part II: Git: A distributed version control system

Version Control with Git. Dylan Nugent

Version Control with Git

Version control. with git and GitHub. Karl Broman. Biostatistics & Medical Informatics, UW Madison

Version control with GIT

MOOSE-Based Application Development on GitLab

MATLAB & Git Versioning: The Very Basics

CPSC 491. Today: Source code control. Source Code (Version) Control. Exercise: g., no git, subversion, cvs, etc.)

Two Best Practices for Scientific Computing

Introduction to Version Control

Git - Working with Remote Repositories

Git. A Distributed Version Control System. Carlos García Campos carlosgc@gsyc.es

Annoyances with our current source control Can it get more comfortable? Git Appendix. Git vs Subversion. Andrey Kotlarski 13.XII.

Version control. HEAD is the name of the latest revision in the repository. It can be used in subversion rather than the latest revision number.

An Introduction to Mercurial Version Control Software

Version Control with Subversion

Introduction to the Git Version Control System

Version Control! Scenarios, Working with Git!

Introduction to Version Control with Git

Dalhousie University CSCI 2132 Software Development Winter 2015 Lab 7, March 11

Git Basics. Christian Hanser. Institute for Applied Information Processing and Communications Graz University of Technology. 6.

CS 2112 Lab: Version Control

Source Control Systems

Pro Git. Scott Chacon *

Version Control with Git

Introducing Xcode Source Control

Version Control for Computational Economists: An Introduction

Using Subversion in Computer Science

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer GIT

Introduc)on to Version Control with Git. Pradeep Sivakumar, PhD Sr. Computa5onal Specialist Research Compu5ng, NUIT

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger

Version Control with Subversion and Xcode

Version Control Systems: SVN and GIT. How do VCS support SW development teams?

Software Configuration Management and Continuous Integration

CSCB07 Software Design Version Control

Work. MATLAB Source Control Using Git

Version Control Systems

Data management on HPC platforms

CSE 374 Programming Concepts & Tools. Laura Campbell (Thanks to Hal Perkins) Winter 2014 Lecture 16 Version control and svn

Using Git for Centralized and Distributed Version Control Workflows - Day 3. 1 April, 2016 Presenter: Brian Vanderwende

Introduction to Version Control with Git

An Introduction to Mercurial Version Control Software

Advanced Computing Tools for Applied Research Chapter 4. Version control

Derived from Chris Cannam's original at, an.

Version Control Script

Using GitHub for Rally Apps (Mac Version)

CISC 275: Introduction to Software Engineering. Lab 5: Introduction to Revision Control with. Charlie Greenbacker University of Delaware Fall 2011

An Introduction to Git Version Control for SAS Programmers

Miguel A. Figueroa Villanueva Xabriel J. Collazo Mojica. ICOM 5047 Capstone Miguel A. Figueroa Villanueva University of Puerto Rico Mayagüez Campus

Distributed Version Control with Mercurial and git

Source Code Management for Continuous Integration and Deployment. Version 1.0 DO NOT DISTRIBUTE

Working Copy 1.4 users manual

Version control with Subversion

Version Control Tutorial using TortoiseSVN and. TortoiseGit

A Git Development Environment

The Hitchhiker s Guide to Github: SAS Programming Goes Social Jiangtang Hu d-wise Technologies, Inc., Morrisville, NC

Revision control systems (RCS) and

Introduction to Subversion

AVOIDING THE GIT OF DESPAIR

Content. Development Tools 2(63)

Git, GitHub & Web Hosting Workshop

Version Control with Mercurial and SSH

Using SVN to Manage Source RTL

Software configuration management

ECE 4750 Computer Architecture, Fall 2015 Tutorial 2: Git Distributed Version Control System

Putting It All Together. Vagrant Drush Version Control

Version Control Using Subversion. Version Control Using Subversion 1 / 27

A Brief Introduction to the Command Line and Git

Continuous Integration. CSC 440: Software Engineering Slide #1

Version Control Tools

Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering Department of

Software Version Control With Mercurial and Tortoise Hg

PKI, Git and SVN. Adam Young. Presented by. Senior Software Engineer, Red Hat. License Licensed under

Git in control of your Change Management

Distributed Version Control

Unity Version Control

Continuous Integration

Developer Workshop Marc Dumontier McMaster/OSCAR-EMR

BlueJ Teamwork Tutorial

Source Control Guide: Git

Xcode Source Management Guide. (Legacy)

Transcription:

Git Basics Christopher Simpkins chris.simpkins@gatech.edu Chris Simpkins (Georgia Tech) CS 2340 Objects and Design CS 1331 1 / 22

Version Control Systems Records changes to files over time Allows you to recover older versions of a file (effectively undoing recent chagnes) Many people already do this manually by saving copies of files with version information embedded in the file name, or automatically using a commercial solutions such as Apple s Time Machine. Neither of these approaches is sufficiently powerful for professional software development. Chris Simpkins (Georgia Tech) CS 2340 Objects and Design CS 1331 2 / 22

Local Version Control Systems RCS - Revision Control System Stores file versions as diffs Any version of the file is constructed by applying each of the diffs in order from the original file. Can be used by a team if team has access to a central machine (over ssh, for example), but very clumsy. Chris Simpkins (Georgia Tech) CS 2340 Objects and Design CS 1331 3 / 22

Centralized Version Control Systems Central server contains the version database Programmers check out the project on their local computers Each programmer is dependent on central server Most popular VCS architecture (CVS, SVN, MKS, Perforce, StarTeam, etc.) Chris Simpkins (Georgia Tech) CS 2340 Objects and Design CS 1331 4 / 22

Locking Models Pessimistic locking (most commercial VCSes) When one programmer has a file checked out no one else can edit it. Optimistic locking (Most open-source VCSes - CVS, SVN, Git, Hg) Files aren t locked. If two people edit a file, the first committer wins - the second person must resolve conflicts before committing their changes Optimistic locking generally preferred, but... Centralized VCSes can encourage infrequent commits to delay the hassle of conflict resolution. Distributed VCSes eliminate this problem by decoupling commits from merges ( pushes in Git parlance). Chris Simpkins (Georgia Tech) CS 2340 Objects and Design CS 1331 5 / 22

Distributed Verson Control Systems Each programmer has a local version of the repository Every repository is equal - no central authoritative repsitory (by default, at least) Each repository contains the entire project and all of its history Commits are made to the local repository Repositories are updated with changes from other repositories by merging the repositories Chris Simpkins (Georgia Tech) CS 2340 Objects and Design CS 1331 6 / 22

Git Created in 2005 by Linus Torvalds to manage the Linux Kernel Super fast and proven in large open source projects Probably the leading DVCS in use today We ll use Git, and the GitHub hosting service in this class Many prospective employers ask to see your GitHub projects. After this class, you ll have something to show them. Chris Simpkins (Georgia Tech) CS 2340 Objects and Design CS 1331 7 / 22

Git Concepts Git stores snapshots of the entire project, not file diffs. Every commit contains references to each of the files in the project, some of which may have changed for the particular commit. Pictorially: In Git, every operation you do in normal day-to-day development is local, making it very fast and independent of central repositories or network access. Chris Simpkins (Georgia Tech) CS 2340 Objects and Design CS 1331 8 / 22

Local Git Workflow To Git, a tracked file can be in one of three states: modified - working copy is different from repository version staged - working copy has been marked for inclusion in the next commit committed - working copy matches repository version Pictorially, the local workflow looks like this: Chris Simpkins (Georgia Tech) CS 2340 Objects and Design CS 1331 9 / 22

Setting Up Git Git configuration stored in three files (on Unix systems): /etc/gitconfig contains settings for every user on the system /.gitconfig contains settings for a specific user, overriding values in /etc/gitconfig.git/config contains settings for a particular reporsitory, overriding values in /.gitconfig and /etc/gitconfig After you install Git, you ll want to configure your identity and your editor $ git config --global user.name "Chris Simpkins" $ git config --global user.email chris.simpkins@gmail.com $ git config --global core.editor emacs You can configure settings for the local repository by leaving off the -global option. Chris Simpkins (Georgia Tech) CS 2340 Objects and Design CS 1331 10 / 22

Initializing a Local Repository To create a local Git repository, run git init $ git init Initialized empty Git repository in /Users/chris/git-demo/.git/ Local repositories are stored in a.git subdirectory of your working directory. Now create a file: $ touch README.rst $ ls README.rst Chris Simpkins (Georgia Tech) CS 2340 Objects and Design CS 1331 11 / 22

Getting the Status of a Working Directory Run git status to get a picture of your local working directory: $ git status # On branch master # # Initial commit # # Untracked files: # (use "git add <file>..." to include in what will be committed) # # README.rst nothing added to commit but untracked files present (use "git add" to track) Usually Git tells you what you need to do next. In this case, we need to run git add to track the README.rst file. Chris Simpkins (Georgia Tech) CS 2340 Objects and Design CS 1331 12 / 22

Adding Files to be Tracked git add adds a file to the staging area (a.k.a. cache, a.k.a. index) to be included in the next commit: $ git add README.rst $ git status # On branch master # # Initial commit # # Changes to be committed: # (use "git rm --cached <file>..." to unstage) # # new file: README.rst Remember, a file can be tracked or untracked, and a tracked file can be in one of three states: modified - working copy is different from repository version staged - working copy marked for inclusion in next commit committed - working file same as in repository Chris Simpkins (Georgia Tech) CS 2340 Objects and Design CS 1331 13 / 22

Comitting Files to the Repository Once a file has been staged, it can be committed to the repository with the git commit command: $ git commit -m "Initial commit." README.rst [master (root-commit) 1d84037] Initial commit. 0 files changed create mode 100644 README.rst The -m option is the commit message. If you leave it off, Git invokes your core.editor (vi if you didn t configure one) so you can add one. Now all our files are committed: ï 1 $ git status 4 # On branch master nothing to commit (working directory clean) Every time we make changes to the file, we add the changed file to the repository with the same two step process: git add to stage the file for inclusion in the next commit git commit to add the changed file to the respository Chris Simpkins (Georgia Tech) CS 2340 Objects and Design CS 1331 14 / 22

Unstaging Modified Files Say we stage a change that we want to undo: $ echo "This is the REDME file for the project." >> README.rst $ git add README.rst As usual, git status tells us what to do: $ git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: README.rst To unstage a file that we staged with git add, use git reset HEAD: $ git reset HEAD README.rst Unstaged changes after reset: M README.rst Chris Simpkins (Georgia Tech) CS 2340 Objects and Design CS 1331 15 / 22

Unmodifying Files Say we have changes we want to get rid of by replacing our working file with the version in the respository. git status tells us how: $ git status # On branch master # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: README.rst # no changes added to commit (use "git add" and/or "git commit -a") Doing what git status tells us reverts the file. $ git checkout -- README.rst $ git status # On branch master nothing to commit (working directory clean) Be careful with this command - it overwrites your working copy. Chris Simpkins (Georgia Tech) CS 2340 Objects and Design CS 1331 16 / 22

Creating a GitHub Repository Log in to github.storm.gatech.edu, Click on Create a New Repo: Make it private, and check the option to create a README: Chris Simpkins (Georgia Tech) CS 2340 Objects and Design CS 1331 17 / 22

Adding Collaborators On the repo page, click Settings: On the settings page, click Collaborators and add me as a collaborator (I m csimpkins on GitHub): Chris Simpkins (Georgia Tech) CS 2340 Objects and Design CS 1331 18 / 22

Cloning to Your Local Machine Back on the repo page, copy the Git URL to your clipboard: On your local machine, go to the directory where you want your working copy to live and clone the remote GitHub repository like this: $ git clone git@github.com:csimpkins/cs2340-hw.git Cloning into cs2340-hw... remote: Counting objects: 3, done. remote: Compressing objects: 100% (2/2), done. remote: Total 3 (delta 0), reused 0 (delta 0) Receiving objects: 100% (3/3), done. $ cd cs2340-hw/ $ ls README.md Chris Simpkins (Georgia Tech) CS 2340 Objects and Design CS 1331 19 / 22

Working With Remotes A remote repository is a copy of the repository that s on another machine on the network or Internet. The GitHub repository we just created is a remote. Every remote repository has a name (you can list all your remotes with git remote -v). When you clone a remote, that remote automatically get sthe name origin. Collaborating with others means pushing changes to remotes and pulling changes from remotes. You can have any number of remote repositories and push, fetch, and pull on any branch. For now we ll focus on our single GitHub remote and the master branch. Chris Simpkins (Georgia Tech) CS 2340 Objects and Design CS 1331 20 / 22

Pushing Changes To Your Remote In Git parlance, pushing means uploading to the remote repository. When you ve committed your changes to your local repo and want to share them (or simply back them up to your remote) do a git push: $ git push origin master origin is the name of your remote, which was set up automatically because you cloned it. master is the name of the branch you re pushing. For now you ll always be on master, which is the default. To update your local repository with changes from your remote, you use it fetch or git pull. We ll discuss that in the next Git lesson. Chris Simpkins (Georgia Tech) CS 2340 Objects and Design CS 1331 21 / 22

Closing Thoughts Version control isn t just for program source code. Learn to store all of your important files in version controllable, diffable, command-line manipulable plain text. You now have a general idea how to work with Git. You need much more practice. Read the first three chapters of Pro Git. Your first homework will be setting up your GitHub account. Create practice projects and experiment. Chris Simpkins (Georgia Tech) CS 2340 Objects and Design CS 1331 22 / 22