Git basic stanley hsiao 2010_12_15

35
Git Basic2 Stanley Hsiao 2010.12.15

description

 

Transcript of Git basic stanley hsiao 2010_12_15

Page 1: Git basic stanley hsiao 2010_12_15

Git Basic2

Stanley Hsiao2010.12.15

Page 2: Git basic stanley hsiao 2010_12_15

Caution!!• Note that this is not a step-by-step tutorial• Contains only some concepts and illustrations

Page 3: Git basic stanley hsiao 2010_12_15

Resource• Books– Progit• Online book written by Scott Chacon

– The Git Community Book• maintained by Scott Chacon

• Interface Tools– http://git-scm.com/tools• TortoiseGit (Windows)

– TortoiseGit is a port of the popular TortoiseSVN project to Git.

Page 4: Git basic stanley hsiao 2010_12_15

Pro git http://progit.org/book/

• 1. Getting Started– 1.1 - About Version Control– 1.2 - A Short History of Git– 1.3 - Git Basics– 1.4 - Installing Git– 1.5 - First-Time Git Setup– 1.6 - Getting Help– 1.7 - Summary

• 2. Git Basics– 2.1 - Getting a Git Repository– 2.2 - Recording Changes to the Repository– 2.3 - Viewing the Commit History– 2.4 - Option Description of Output– 2.5 - %s Subject– 2.6 - Option Description– 2.7 - Option Description– 2.8 - Undoing Things– 2.9 - Working with Remotes– 2.10 - Tagging– 2.11 - Tips and Tricks– 2.12 - Summary

Page 5: Git basic stanley hsiao 2010_12_15

Git Basics• Chapter 2• Git Basics• If you can read only one chapter to get going with Git, this is it.

– 2.1 - Getting a Git Repository git init, git clone– 2.2 - Recording Changes to the Repository git status, git add, git commit– 2.3 - Viewing the Commit History git log, – 2.4 - Option Description of Output– 2.5 - %s Subject– 2.6 - Option Description– 2.7 - Option Description– 2.8 - Undoing Things git reset– 2.9 - Working with Remotes git remote, git fetch, git push– 2.10 - Tagging git tag, git show,– 2.11 - Tips and Tricks git ….– 2.12 - Summary

Page 6: Git basic stanley hsiao 2010_12_15

Single user version control

Page 7: Git basic stanley hsiao 2010_12_15

Outline• Basic Command of revision control software• Review Branch in git– Understanding git log– Detached Head State

• Merge VS. Rebase

Page 8: Git basic stanley hsiao 2010_12_15

Basic Commands

Software 

repository init 

clone  pull  push 

local branches 

checkout  update  lock  add  remove  move  copy  merge  commit  revert 

generate bundle file 

rebase

Git init / init --bare clone fetch

[72] push branch clone pullUnknown

add rm mv

cp [then] git add[73]

merge commit checkout bundle reba

se

Page 9: Git basic stanley hsiao 2010_12_15

Git Basics• Nearly Every Operation Is Local

Page 10: Git basic stanley hsiao 2010_12_15

REVIEW BRANCH IN GIT

Page 11: Git basic stanley hsiao 2010_12_15

Head

Page 12: Git basic stanley hsiao 2010_12_15

Review of Branch

Page 14: Git basic stanley hsiao 2010_12_15

Git overview

https://github.com/swem/training-for-using-git/

Page 15: Git basic stanley hsiao 2010_12_15

git log

Page 16: Git basic stanley hsiao 2010_12_15

git log –decorate=full

Page 17: Git basic stanley hsiao 2010_12_15

git log –decorate=full

Page 18: Git basic stanley hsiao 2010_12_15

Understanding git log• refs/heads/master• refs/heads/new_branch• HEAD• refs/remotes/origin/master• refs/remotes/origin/new_branch• tag: refs/tags/v0.1• tag: refs/tags/v0.2

• Recommend reading especially http://progit.org/book/ch3-5.html

Page 19: Git basic stanley hsiao 2010_12_15

“Detached head” state

Page 20: Git basic stanley hsiao 2010_12_15

“Detached head” state• git checkout– Branchhead Example: git checkout my_bch– Arbitrary commit Example: git checkout 48eeb5• “Detached head” state

Page 21: Git basic stanley hsiao 2010_12_15

“Detached head” state• Examining an old version without creating a

new branch

• it means the HEAD file points directly to a commit, not to a symbolic reference.

Page 22: Git basic stanley hsiao 2010_12_15

“Detached head” stateit means the HEAD file points directly to a commit, not to a symbolic reference.

Page 23: Git basic stanley hsiao 2010_12_15

“Detached head” statePros• easy way to check out a

particular version without having to make up a name for the new branch.

• You can still create a new branch (or tag) for this version later if you decide to.

Cons• The issue is that you

generally don’t want to work in a detached head environment, because it’s easy to lose changes.

Page 24: Git basic stanley hsiao 2010_12_15

MERGE VS. REBASE

Page 25: Git basic stanley hsiao 2010_12_15

Merge BranchBEFORE AFTER

Page 26: Git basic stanley hsiao 2010_12_15

Rebase BranchBEFORE AFTER

Page 27: Git basic stanley hsiao 2010_12_15

Rebase Branch• Do not rebase commits that you have pushed to a public repository.– http://progit.org/book/ch3-6.html

Page 28: Git basic stanley hsiao 2010_12_15

Multi-user version control

Page 29: Git basic stanley hsiao 2010_12_15

Remote• open source software hosting facilities:– http://en.wikipedia.org/wiki/Comparison_of_ope

n_source_software_hosting_facilities• One of these– GitHub

Page 30: Git basic stanley hsiao 2010_12_15

github• SSH channel– Get help with generating ssh keys

http://help.github.com/

Page 31: Git basic stanley hsiao 2010_12_15

github

Page 32: Git basic stanley hsiao 2010_12_15

github

Page 33: Git basic stanley hsiao 2010_12_15

git push• Example in

http://www.kernel.org/pub/software/scm/git/docs/git-push.html

• git push (remote) (branch):– Example: git push origin my_branch

• you have to explicitly push the branches you want to share.

Page 34: Git basic stanley hsiao 2010_12_15

git push• you have to explicitly push the branches you

want to share.– That way, you can use private branches for work

you don’t want to share, and push up only the topic branches you want to collaborate on.

Page 35: Git basic stanley hsiao 2010_12_15

References• http://progit.org/book/• http://www.kernel.org/pub/software/scm/git/

docs/user-manual.html