git tutorial i

39
Git Tutorial Jim Yeh < [email protected] >

Upload: chang-ching-yeh

Post on 27-Jun-2015

127 views

Category:

Technology


0 download

DESCRIPTION

Git Tutorial

TRANSCRIPT

Page 1: Git Tutorial I

Git Tutorial Jim Yeh <[email protected]>

Page 2: Git Tutorial I

About Me

• Full-stack Engineer

• Python since 2006 Javascript since 2010 Git since 2011

Page 3: Git Tutorial I

• Introduction

• Hands on Git

• Local repository

• Remote repository

Hackpad: http://tinyurl.com/nccumath-git

Outline

Page 4: Git Tutorial I

What is Git?

• Source Code Management system (SCM)

• Distributed Version Control System (DVCS)

• Created by Linus Torvalds

Page 5: Git Tutorial I

Why Git?

• Collaboration

• Version control

• Track development history

• Distributed

• Not only source code

Page 6: Git Tutorial I

Setup environment

• On ubuntu, apt-get install git

• On mac, brew install git or use git-scm for mac

• On windows, use git-scm for windows

Page 7: Git Tutorial I

Repository

• A project

• Local and Remote

Page 8: Git Tutorial I

Clone a Repository

• git clone <repo path>

• git status

Local Remotegit clone

Page 9: Git Tutorial I

Log

• Display commit records

• git log --color --graph --all --decorate

Page 10: Git Tutorial I

Exercise 1

• Clone the following project: https://github.com/nccumath/git-exercise-1.git

• Check its status.

Page 11: Git Tutorial I

Local Repository

Page 12: Git Tutorial I

Config

• git config --global user.name "Jim Yeh"

• git config --global user.email “[email protected]

• git config --global core.editor "notepad++.exe -multiInst"

• git config --global -l

Page 13: Git Tutorial I

Phases

• Workspace (unstaged) - Update documents.

• Staging Area (staged)- Ready for submit (commit).

• Repository (committed) - Submitted.

Workspace Staging Area

Local Repository

Page 14: Git Tutorial I

Submit your code

• git add <filename>

• git reset HEAD <filename>

• git commit

Page 15: Git Tutorial I

Submit your code

• git add <filename>

• git reset HEAD <filename>

• git commit

Stage

Page 16: Git Tutorial I

Submit your code

• git add <filename>

• git reset HEAD <filename>

• git commit

Stage

Unstage

Page 17: Git Tutorial I

Submit your code

• git add <filename>

• git reset HEAD <filename>

• git commit

Stage

Unstage

Commit

Page 18: Git Tutorial I

Commit number

• ID number for each commit

• Use for many configuration

Page 19: Git Tutorial I

Local Workflow

Workspace Staging Area

Local Repository

git add

git commit

git rest HEAD

Page 20: Git Tutorial I

Examine changes

• Check difference between two commit by git diff

• git diff <old-commit> <new-commit>

Page 21: Git Tutorial I

Exercise 2

• Add a new file named to your SID.

• Commit the file.

Page 22: Git Tutorial I

Branch

• There is at least one branch in a repository.

• Default branch is called master branch

Page 23: Git Tutorial I

Branch operation

• git branch

• git branch <branch name>

• git checkout <branch name>

Page 24: Git Tutorial I

Exercise 3

• Create a branch in your SID

• Checkout to that branch

• Update introduction.txt

• Commit your update

Page 25: Git Tutorial I

Keyword Review

Page 26: Git Tutorial I

Noun

• Repository

• Branch

• Commit

Page 27: Git Tutorial I

Noun

• Repository

• Branch

• Commit Dot

Page 28: Git Tutorial I

Noun

• Repository

• Branch

• Commit

Line

Dot

Page 29: Git Tutorial I

Noun

• Repository

• Branch

• Commit

Line

Dot

Surface

Page 30: Git Tutorial I

Noun

• Repository

• Branch

• Commit

Line

Dot

Surface

Page 31: Git Tutorial I

Noun

• Repository

• Branch

• Commit

Line

Dot

Surface Tree

Page 32: Git Tutorial I

Verb

Stage

Unstage

Commit

Page 33: Git Tutorial I

Remote

Page 34: Git Tutorial I

GitHub

• http://www.github.com

• A web-based hosting service for Git

• Provide a platform for comments, wiki and issue tracking.

Page 35: Git Tutorial I

Sign up

Page 36: Git Tutorial I

Remote Info

• git remote

• git remote show

• git remote add <name> <url>

Page 37: Git Tutorial I

Push / Pull

• git push <remote> <branch>

• git pull <remote> <branch>Local Remote

git push

git pull

Page 38: Git Tutorial I

Exercise 4

• Push your branch to remote.

Page 39: Git Tutorial I

Q & A