Get on with git

25
habeeb rahman | [email protected] | [email protected] Get on with Git

Transcript of Get on with git

Page 1: Get on with git

habeeb rahman | [email protected] | [email protected]

Get on with Git

Page 2: Get on with git

topics

git waybasic commands

Page 3: Get on with git

git way

direct acyclic graph

sha-1 hash

git objects: blob tree commit tag

Page 4: Get on with git

sha-1 & blob

(master) $ echo -e 'blob 14\0Hello, World!' | shasum8ab686eafeb1f44702738c8b0f24f2567c36da6d

(master) $ echo 'Hello, World!' | git hash-object -w --stdin8ab686eafeb1f44702738c8b0f24f2567c36da6d

(master) $ ls .git/objects/8ab686eafeb1f44702738c8b0f24f2567c36da6d

(master) $ git show 8ab686eafeb1f44702738c8b0f24f2567c36da6dHello, World!

Page 5: Get on with git

sha-1 & blob

(master)$ git cat-file -p 8ab686eafeb1f44702738c8b0f24f2567c36da6dHello, World!

(master)$ git cat-file -t 8ab686eafeb1f44702738c8b0f24f2567c36da6dblob

Page 6: Get on with git

sha-1 and tree

git cat-file -p master^{tree}

Page 7: Get on with git

sha-1 and commit

(master)$ git showcommit 0184521b4bc88bbb67891ed740140147c9ce61cdAuthor: Habeeb Rahman <[email protected]>Date:......

(master)$ git cat-file -t 0184521b4bc88bbb67891ed740140147c9ce61cdcommit

Page 8: Get on with git

behind the sceneworking directory

working directory git add

committed snapshotgit commit

index(stage)

Page 9: Get on with git

Basic commands

Page 10: Get on with git

first things first

let git know your name and email:

git config --global user.name "Your Name"git config --global user.email "[email protected]"

Page 11: Get on with git

git init

Create an empty git repository or reinitialize an existing one

$ mkdir getonwithgit$ cd getonwithgit/$ git initInitialized empty Git repository in /Users/hrahman/test/getonwithgit/.git/

Page 12: Get on with git

git add

(master)$ echo "Hello World" > hello.txt(master)$ git status# On branch master# Initial commit# Untracked files:# (use "git add <file>..." to include in what will be committed)# hello.txtnothing added to commit but untracked files present (use "git add" to track)(master)$ git add hello.txt(master)$ git status# On branch master# Initial commit# Changes to be committed:# (use "git rm --cached <file>..." to unstage)# new file: hello.txt

Page 13: Get on with git

git commit

(master)$ git commit -m "first commit"[master (root-commit) 05e96c3] first commit 1 files changed, 1 insertions(+), 0 deletions(-) create mode 100644 hello.txt(master)$ git showcommit 05e96c39452126e9310e84203af72f141c37a493Author: Habeeb Rahman <[email protected]>Date: Tue Jun 18 13:46:35 2013 +0530 first commitdiff --git a/hello.txt b/hello.txtnew file mode 100644index 0000000..557db03--- /dev/null+++ b/hello.txt@@ -0,0 +1 @@+Hello World

Page 14: Get on with git

git diff

git diff: Show differences between your working directory and the index.

git diff –cached: Show differences between the index and the

most recent commit. git diff HEAD: Show the differences between your working

directory and the most recent commit.

Page 15: Get on with git

git commit --amend

you commit and then realize you forgot to stage the changes in a file you wanted to add to this commit:$ git commit -m 'initial commit'$ git add forgotten_file$ git commit --amend

Page 16: Get on with git

branch

create a new branch:(master)$ git checkout -b dev_featureSwitched to a new branch 'dev_feature'

switch to an existing branch:(dev_feature)$ git checkout masterSwitched to branch 'master'(dev_feature)$ echo "new feature" > feature.txt(dev_feature)$ git add feature.txt(dev_feature)$ git commit -m "feature"

Page 17: Get on with git

branch

delete a branch$git branch -d dev_new_branch

show all local branches:$git branch

show all local and remote branches:$git branch -a

Page 18: Get on with git

branch & merge

Page 19: Get on with git

mergemerge 'dev_feature' branch into 'master':(dev_feature)$ git checkout masterSwitched to branch 'master'find out what's going to be merged:(master)$ git diff master...dev_featurediff --git a/feature.txt b/feature.txtnew file mode 100644index 0000000..2c61ec4--- /dev/null+++ b/feature.txt@@ -0,0 +1 @@+new feature added(master)$ git merge dev_featureUpdating 05e96c3..70c1e30Fast-forward feature.txt | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) create mode 100644 feature.txt

Page 20: Get on with git

git blame

(master)$ git blame feature.txt70c1e306 (Habeeb Rahman 2013-06-18 15:50:47 +0530 1) new feature added

Page 21: Get on with git

git log

(master)$ git logcommit 70c1e3069a68877fca9680b045185288c5201a46Author: Habeeb Rahman <[email protected]>Date: Tue Jun 18 15:50:47 2013 +0530

featurecommit 05e96c39452126e9310e84203af72f141c37a493Author: Habeeb Rahman <[email protected]>Date: Tue Jun 18 13:46:35 2013 +0530

first commit

(master)$ git log --oneline70c1e30 feature05e96c3 first commit

Page 22: Get on with git

git grep

(master)$ git grep hellohello.txt:hello worldnew.txt:hello everyone

Page 23: Get on with git

git clone

Local:git clone /path/to/repositoryRemote:git clone git://github.com/sample/test.git

Page 24: Get on with git

git help

display help information about git$ git help help$ git help grep$ git help reset

Page 25: Get on with git

further reading

http://git-scm.com/bookhttp://think-like-a-git.net/http://ftp.newartisans.com/pub/git.from.bottom.up.pdf