Git Tutorial I

Post on 27-Jun-2015

122 views 0 download

Tags:

description

Git Tutorial

transcript

Git Tutorial Jim Yeh <lemonlatte@gmail.com>

About Me

• Full-stack Engineer

• Python since 2006 Javascript since 2010 Git since 2011

• Introduction

• Hands on Git

• Local repository

• Remote repository

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

Outline

What is Git?

• Source Code Management system (SCM)

• Distributed Version Control System (DVCS)

• Created by Linus Torvalds

Why Git?

• Collaboration

• Version control

• Track development history

• Distributed

• Not only source code

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

Repository

• A project

• Local and Remote

Clone a Repository

• git clone <repo path>

• git status

Local Remotegit clone

Log

• Display commit records

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

Exercise 1

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

• Check its status.

Local Repository

Config

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

• git config --global user.email “lemonlatte@gmail.com”

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

• git config --global -l

Phases

• Workspace (unstaged) - Update documents.

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

• Repository (committed) - Submitted.

Workspace Staging Area

Local Repository

Submit your code

• git add <filename>

• git reset HEAD <filename>

• git commit

Submit your code

• git add <filename>

• git reset HEAD <filename>

• git commit

Stage

Submit your code

• git add <filename>

• git reset HEAD <filename>

• git commit

Stage

Unstage

Submit your code

• git add <filename>

• git reset HEAD <filename>

• git commit

Stage

Unstage

Commit

Commit number

• ID number for each commit

• Use for many configuration

Local Workflow

Workspace Staging Area

Local Repository

git add

git commit

git rest HEAD

Examine changes

• Check difference between two commit by git diff

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

Exercise 2

• Add a new file named to your SID.

• Commit the file.

Branch

• There is at least one branch in a repository.

• Default branch is called master branch

Branch operation

• git branch

• git branch <branch name>

• git checkout <branch name>

Exercise 3

• Create a branch in your SID

• Checkout to that branch

• Update introduction.txt

• Commit your update

Keyword Review

Noun

• Repository

• Branch

• Commit

Noun

• Repository

• Branch

• Commit Dot

Noun

• Repository

• Branch

• Commit

Line

Dot

Noun

• Repository

• Branch

• Commit

Line

Dot

Surface

Noun

• Repository

• Branch

• Commit

Line

Dot

Surface

Noun

• Repository

• Branch

• Commit

Line

Dot

Surface Tree

Verb

Stage

Unstage

Commit

Remote

GitHub

• http://www.github.com

• A web-based hosting service for Git

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

Sign up

Remote Info

• git remote

• git remote show

• git remote add <name> <url>

Push / Pull

• git push <remote> <branch>

• git pull <remote> <branch>Local Remote

git push

git pull

Exercise 4

• Push your branch to remote.

Q & A