introduction to git

14
Intro to GIT Gharpay – Friday 3/08/2012 Arpit Mohan

Upload: arpit-mohan

Post on 16-May-2015

135 views

Category:

Technology


1 download

DESCRIPTION

This presentation is an introduction to GIT and contains a list of some of the cool features that a VCS can provde.

TRANSCRIPT

Page 1: Introduction to GIT

Intro to GITGharpay – Friday 3/08/2012Arpit Mohan

Page 2: Introduction to GIT

Version Control?

Why?

How?Ctrl-C + Ctrl-V ( Most popular )

Centralized VCS ( Version Control System ) Eg. SVN, Perforce.

Distributed VCS. Eg. Git, Mercurial

When?

Page 3: Introduction to GIT

Salient Features of Git

Distributed VCS. Each system is a complete mirror of the repository.

Data integrity. All data is check-summed and stored as the SHA1-ID.

Differential data. Capability to do-undo changes without fear of data corruption.

Page 4: Introduction to GIT

Install GIT

You already know this! Else, try out the awesome website a few friends, Sergey Brin and Larry Page built – http://www.google.com

Page 5: Introduction to GIT

Git ConfigurationIdentity – Very very important. It helps us identify who you are and what you did. Associated tools like Jenkins, CruiseControl etc use this identity to perform more functions.

$ git config --global user.name ”Arpit Mohan”

$ git config --global user.email [email protected]

$ git config --global core.editor emacs (By default Vi/Vim)

$ git config --global merge.tool vimdiff ( I use Eclipse )

$ git config –list

$ git help <action> - Some old methods never die!

$ git config --global alias.co checkout (You can setup multiple aliases)

All this is stored in ~/.gitconfig file. Check it out.

Page 6: Introduction to GIT

Few Git Paradigms

Working Directory

Staging Area

Git Repository (Local)

Git Repositor

y (Remote)

• Distributed System. Every checkout is a snapshot. No loss of data. Multiple copies.

• Primarily local operations. Very little interaction with remote repository. Hence faster!

Untracked Unmodified Modified Staged Committe

d Pushed

Page 7: Introduction to GIT

Git Commands$ git status

$ git branch (To name the branch)

$ git add <filename> (To begin tracking a new file or stage a file for commit)

$ vi .gitignore (Get Git to ignore files. Eg. Log files)

$ git commit –m “<Commit Message>” <filenames> (-a)

$ git rm <filename> Removes the file from local and repo.

$ git rm --cached <filename>

$ git mv <old_name> <new_file>

Page 8: Introduction to GIT

Git Logs (contd)

$ git log –pretty=oneline (Pretty print the log)

$ git log --pretty=format:"%h - %an, %ar : %s”

$ git log –graph

Page 9: Introduction to GIT

Amending the Tree

$ git commit –amendExample:

$ git commit -m ’initial commit’

$ git add forgotten_file

$ git commit –amend

Be Careful while amending the tree because the changes are permanent!

Page 10: Introduction to GIT

Remote Repository

$ git remote –v ( Name and URL of the remote server)

$ git remote add <branch> <url of remote repo>

$ git fetch <branchname>

$ git remote rm <branchname> ( Use carefully)

$ git pull

Page 11: Introduction to GIT

Git Branches

Git branches are one of the most potent features of Git. Learn it and it may just change your life!

$ git branch (List local branches)-a : List all branches, local and remote

-t : Begin tracking a remote branch

-d : Delete a branch

$ git checkout –b <branchname> origin/branchname (Creates a branch and tracks the remote branchname)

Page 12: Introduction to GIT

Merging & Rebasing

$ git merge <branchname> ( Merging another branch into this )

$ git rebase [basebranch] [topicbranch]( Plays the child commits on the master )

Interesting things can be done with rebase. Look at whiteboard!

IMP: Don’t rebase stuff that has been committed to the remote repository! Such people are hated and stoned

Page 13: Introduction to GIT

Interesting Features

$ git bisect start$ git bisect good

$ git bisect bad

$ git bisect reset

$ git bisect run testing.sh

$ git diff (Useless for binary files)Add *.doc diff=word (In .gitattributes)

$ git config diff.word.textconv strings

Exiftool ( For JPEG Files)

Page 14: Introduction to GIT

Interesting Features

Hooks (Server side and Client side)Pre-commit hooks

Post-commit hooks

$ git gc