Tutorial: Getting Started with Git Introduction to version control - - PowerPoint PPT Presentation

tutorial getting started with git
SMART_READER_LITE
LIVE PREVIEW

Tutorial: Getting Started with Git Introduction to version control - - PowerPoint PPT Presentation

Tutorial: Getting Started with Git Introduction to version control Benefits of using Git Basic commands Workflow 1 CS349 - Git tutorial xkcd http://xkcd.com/1597/ CS349 - Git tutorial 2 Version Control Systems Goal of a Version


slide-1
SLIDE 1

Tutorial: Getting Started with Git

Introduction to version control Benefits of using Git Basic commands Workflow

CS349 - Git tutorial 1

slide-2
SLIDE 2

xkcd

2

http://xkcd.com/1597/

CS349 - Git tutorial

slide-3
SLIDE 3

Version Control Systems

  • Goal of a Version Control System

– Software that manages changes that you make to your files (source code). – Track versions of each file (more accurately, versions

  • f sets of changes to your files).

– Handles concurrent changes from multiple sources (e.g. different developers working on the same code base). – Typically some central repository that stores every version of every file.

3

  • Popular VCS’s

– SourceSafe (local/file based) – CVS, Subversion, Perforce (centralized)

CS349 - Git tutorial

slide-4
SLIDE 4

Distributed Version Control

  • Distributed version control systems (DVCS)

– No central server required! – Every user has a copy of every file.

  • We use Git, a very popular DVCS.

– Developed in 2005, to manage development for the Linux kernel (Bitkeeper -> Git) – Very specific design goals

  • Large-scale development
  • Distributed

4

  • Git doesn’t require a server,

but it’s common to use one for coordination – e.g. Github

CS349 - Git tutorial

slide-5
SLIDE 5

Concepts

  • Working directory

– your local copy of the files that you’re working with.

  • Staging area

– a “place” where you tell Git to hold a set of changes, temporarily.

  • Repository

– a place where Git stores copies of your files and their history.

  • Local repository: on your working machine
  • Remote repository: a server (e.g. GitHub)

5 CS349 - Git tutorial

slide-6
SLIDE 6

6 CS349 - Git tutorial

slide-7
SLIDE 7

Commands

  • You perform these operations using a Git client (command-

line or GUI, the work the same).

  • Commands typically move files between working directory,

staging area and local or remote repository.

7

Local Commands Description git add Add a file from working directory to staging area git commit Commit changes from staging area to repo git checkout Get files from repo to working directory Remote Commands Description git clone Make a copy from remote repo to working dir git pull Pull (merge) changes from repo to working dir git push Push (merge) changes from staging area to repo

CS349 - Git tutorial

slide-8
SLIDE 8

Installing Git Before anything else, you need to install and configure Git.

  • 1. Install a Git client (command-line or GUI)

https://git-scm.com/downloads

  • 2. Setup your email address for Git:

git config --global user.email "your_email@example.com"

8 CS349 - Git tutorial

slide-9
SLIDE 9

Working on A0

  • 1. Get a copy of the repository from the server

– Use ‘git clone’ to get a copy of starting code from remote repository to your working directory.

  • git clone https://username@git.uwaterloo.ca/cs349-

winter2017/username.git

  • 2. Work on the assignment
  • 3. Save and commit your changes to git
  • 4. Push changes to the server

9 CS349 - Git tutorial

slide-10
SLIDE 10

Working on A0

  • 1. Get a copy of the repository from the server
  • 2. Work on the assignment

– copy the Check.java file into your working directory. – ‘javac Check.java’ to compile – ‘java Check’ to run and produce results.txt

  • 3. Save and commit your changes to git
  • 4. Push changes to the server

10 CS349 - Git tutorial

slide-11
SLIDE 11

Working on A0

  • 1. Get a copy of the repository from the server
  • 2. Work on the assignment
  • 3. Save and commit your changes to git

– ‘git add Check.java results.txt’ to add files to your staging area – ‘git commit’ to save the changes to the local repository.

  • 4. Push changes to the server

11 CS349 - Git tutorial

slide-12
SLIDE 12

Working on A0

  • 1. Get a copy of the repository from the server
  • 2. Work on the assignment
  • 3. Save and commit your changes to git
  • 4. Push changes to the server

– ‘git push’ to push to the remote repository.

12 CS349 - Git tutorial

slide-13
SLIDE 13

“Good Ideas”

  • 1. Edit .gitignore file in your working copy
  • 2. Consider cloning via SSH or HTTPS.

– For SSH, generate public/private keys.

  • https://git.uwaterloo.ca/help/ssh/README

– If you use HTTPS, you might want to cache credentials

  • https://git-scm.com/docs/git-credential-store
  • 3. Learn how to use tags or branches

– See documentation

13 CS349 - Git tutorial

slide-14
SLIDE 14

Resources

  • Git Home

– documentation, binaries – https://git-scm.com

  • Git Reference

– cheat-sheet of commands – http://gitref.org

  • Book: Pro Git

– Scott Chacon and Ben Straub – extensive manual

  • Ry’s Git Tutorial

– http://rypress.com/tutorials/git/ index

14 CS349 - Git tutorial