Git for-fun-and-productivity

42
kartzontech For Fun And Productivity Karthik Sirasanagandla

description

 

Transcript of Git for-fun-and-productivity

Page 1: Git for-fun-and-productivity

kartzontech

For Fun And Productivity

Karthik Sirasanagandla

Page 2: Git for-fun-and-productivity

kartzontech

Page 3: Git for-fun-and-productivity

Why Git?

kartzontech

Page 4: Git for-fun-and-productivity

Speed

kartzontech

Page 5: Git for-fun-and-productivity

Space Compactness

kartzontech

Mozilla repo.

12 GB in SVN

Mozilla repo.

420 MB in Git

Page 6: Git for-fun-and-productivity

Distributed VCS

kartzontech

SVN Git

Page 7: Git for-fun-and-productivity

Resilience

kartzontech

Page 8: Git for-fun-and-productivity

Branching

kartzontech

Time, Space..

and fun!!..

Page 9: Git for-fun-and-productivity

Git Server

kartzontech

*Best place to look for to set up git server is http://git-scm.com/book/en/Git-on-the-Server

Page 10: Git for-fun-and-productivity

FREE Hosting Services

kartzontech

Page 11: Git for-fun-and-productivity

kartzontech

Any cons?And what's the way out?

Page 12: Git for-fun-and-productivity

kartzontech

• Git Workflow is different

• Be ready to UN-LEARN

• Un-sophisticated UI clients

• Git CLI is cool and friendly. Use It!

• Git is not a server by itself.

• That’s unlike SVN, CVS, etc.

• But, that’s okay - really!

Page 13: Git for-fun-and-productivity

kartzontech

TheoryWhat You MUST Know!

Page 14: Git for-fun-and-productivity

kartzontech

Nearly everything is local

Browse logsCompare Diff

Local Commits

Local Branches

Page 15: Git for-fun-and-productivity

kartzontech

Snapshots Not Differences

SVN

Git

Page 16: Git for-fun-and-productivity

kartzontech

The

Git Object Model

Page 17: Git for-fun-and-productivity

kartzontech

• 40-digit alphanumeric “object name”

• look like 70a114563ec375ff9ecf335fdc4ac27027a454b4

• SHA 1 hash of the object contents

• SHA 1 is a cryptographic hash function

• SHA 1 helps determine object uniqueness

SHA - The Foundation

Page 18: Git for-fun-and-productivity

kartzontech

• Blob

• file contents

• chunk of binary data

• doesn’t have any attributes

• .. not even file name

• renaming file doesn’t change this object

• its location independent (in directory tree)

• Want to see blob contents?git show <sha_of_blob>

4 Object Types - The Blob

Page 19: Git for-fun-and-productivity

kartzontech

• Tree• represents contents of a (sub-)directory• has pointers to blobs and other (sub-)trees

• Want to see Tree contents?git [show | ls-tree] <sha_of_tree>

4 Object Types - The Tree

Page 20: Git for-fun-and-productivity

kartzontech

• Commit• links physical state of tree w/

• a description of how we got there (link to parent) and

• why (the commit message)

• Want to not just see but examine your Commit?git log --pretty=rawgit show -s --pretty=raw <sha_of_commit>

4 Object Types - The Commit

Page 21: Git for-fun-and-productivity

kartzontech

Visualizing

Git Object Model

Need a Demo?

Page 22: Git for-fun-and-productivity

kartzontech

• Tag• A way to mark your commit as ‘special’

4 Object Types - Tag

Learn in your leisure..

Page 23: Git for-fun-and-productivity

kartzontech

PracticeWhat You SHOULD Do!

Page 24: Git for-fun-and-productivity

kartzontech

• Copy EXISTING repo.

$ git clone <url_of_remote_repo>

• Create NEW repo

$ mkdir <new_proj_name>

$ cd <new_proj_name>

$ git init

• Check current state of your repo

$ git status

Kick-start Your Work

Page 25: Git for-fun-and-productivity

kartzontech

Persist to your local repo$ git add [filename | foldername]$ git commit -m <my_message>

Modify And Commit

Page 26: Git for-fun-and-productivity

kartzontech

• Rollback change BEFORE staging

$ git checkout <file_name>

• Rollback change AFTER staging

$ git reset HEAD <file_name>

$ git checkout <file_name>

Modify And Rollback

Page 27: Git for-fun-and-productivity

kartzontech

View (Un-)Stanged Changes

Page 28: Git for-fun-and-productivity

kartzontech

• Delete a file in repo

$ rm <file_name>

$ git rm <file_name>

$ git commit -m <commit_message>

Remove it from my repo!

Page 29: Git for-fun-and-productivity

kartzontech

Hasty Dev, I am..

Instead of adding log files to .gitignore,

I hurriedly added them to index (staging area).

$ git add -A .

$ git status# On branch my_pet_feature

# Changes to be committed:

# (use "git reset HEAD <file>..." to unstage)

# new file: errors.log

# new file: out.log

Now.. what do I do?

QUIZ

(Shit that happens..)

Page 30: Git for-fun-and-productivity

kartzontech

Don’t you worry!

Simply “remove the files from index”

$ git rm --cached *.log

$ git status# On branch my_pet_feature

# Untracked files:

# (use "git add <file>..." to include in what will be committed)

# errors.log

# out.log

Page 31: Git for-fun-and-productivity

kartzontech

Page 32: Git for-fun-and-productivity

kartzontech

I confess!

I not only added but did a local commit as well

$ git add -A .

$ git commit -m “bad commit”

QUIZ

(Shittier things happen as well)

Page 33: Git for-fun-and-productivity

kartzontech

No worries!.. You are SAFE!!!$ git reset --soft HEAD^$ git status# On branch my_pet_feature

# Changes to be committed:# (use "git reset HEAD <file>..." to unstage)

# modified: abc.txt

# new file: errors.log# new file: out.log

$ git rm --cached *.log$ git status# On branch my_pet_feature

# Untracked files:

# (use "git add <file>..." to include in what will be committed)# errors.log

# out.log

Alternatively:

$ git reset HEAD^$ git status# On branch my_pet_feature

# Untracked files:# (use "git add <file>..." to include in what will be committed)

# errors.log

# out.log

Page 34: Git for-fun-and-productivity

kartzontech

Page 35: Git for-fun-and-productivity

kartzontech

git reset??

Page 36: Git for-fun-and-productivity

kartzontech

Page 37: Git for-fun-and-productivity

kartzontech

The Routine

1. Show me latest commitsgit log

2. Show me the last 2 commitsgit log -2

3. Show me the patch introduced with each commitgit log -p

4. Show me just the commit messagesgit log --pretty=onelinegit log --oneline

Page 38: Git for-fun-and-productivity

kartzontech

The Fun Stuff

1. Show me the commits for last 2 weeksgit log --since=2.weeks

2. Show me the commits before 3 monthsgit log --before=3.months

3. Show me the commits authored by ‘karthik’ onlygit log --author=karthik

4. Show me just the commit where the commiter is ‘karthik’git log --committer=karthik

Page 39: Git for-fun-and-productivity

kartzontech

QUIZ: Do Try It At Home :)

1. Show me commits made during the first two days of this weekgit log _______________________

2. Show me the commits made since the last half hourgit log _______________________

3. Show me the commits authored by ‘karthik’ for the last 10 daysgit log _______________________

4. Show me just the commits where the commiter is ‘karthik’ and author is ‘ganesh’git log _______________________

5. I’ve a commit (with sha a1fix) to fix a high priority bug in Production. I need to merge these changes in other developmental branches as well. What is the efficient way to do it?

6. I’ve made some really bad local commits in my feature branch. Can I undo it?

Page 40: Git for-fun-and-productivity

Git Server

kartzontech

git init --bare new_repo_name.git

Client 1:git remote add origin <url>git push origin master

git clone <url>

Client 2:

Page 41: Git for-fun-and-productivity

kartzontech

Resources and Recommendations

1. Pro Git by Scott Chacon2. http://git-scm.com/book (FREE online version of Pro Git)3. http://git-scm.com/docs4. http://try.github.io (Got 15 minutes and want to learn Git?)5. Git in the Trenches by Peter Savage (http://cbx33.github.io/gitt/)6. https://git.wiki.kernel.org/index.php/GitSvnComparsion7. http://blog.jessitron.com/

Page 42: Git for-fun-and-productivity

kartzontech

I would really appreciate your feedback...

Please do feel free to drop a note at SpeakerRate (http://speakerrate.com/talks/25891-git-for-fun-and-productivity)