Get on with git


Published on

1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Get on with git

  1. 1. habeeb rahman | | pk.habi@gmail.comGet on with Git
  2. 2. topicsgit waybasic commands
  3. 3. git waydirect acyclic graphsha-1 hashgit objects: blob tree commit tag
  4. 4. sha-1 & blob(master) $ echo -e blob 140Hello, World! | shasum8ab686eafeb1f44702738c8b0f24f2567c36da6d(master) $ echo Hello, World! | git hash-object -w --stdin8ab686eafeb1f44702738c8b0f24f2567c36da6d(master) $ ls .git/objects/8ab686eafeb1f44702738c8b0f24f2567c36da6d(master) $ git show 8ab686eafeb1f44702738c8b0f24f2567c36da6dHello, World!
  5. 5. sha-1 & blob(master)$ git cat-file -p 8ab686eafeb1f44702738c8b0f24f2567c36da6dHello, World!(master)$ git cat-file -t 8ab686eafeb1f44702738c8b0f24f2567c36da6dblob
  6. 6. sha-1 and treegit cat-file -p master^{tree}
  7. 7. sha-1 and commit(master)$ git showcommit 0184521b4bc88bbb67891ed740140147c9ce61cdAuthor: Habeeb Rahman <>Date:......(master)$ git cat-file -t 0184521b4bc88bbb67891ed740140147c9ce61cdcommit
  8. 8. behind the sceneworking directoryworkingdirectory git addcommittedsnapshotgit commitindex(stage)
  9. 9. Basic commands
  10. 10. first things firstlet git know your name and email:git config --global "Your Name"git config --global ""
  11. 11. git initCreate an empty git repository or reinitialize an existing one$ mkdir getonwithgit$ cd getonwithgit/$ git initInitialized empty Git repository in /Users/hrahman/test/getonwithgit/.git/
  12. 12. 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
  13. 13. git commit(master)$ git commit -m "first commit"[master (root-commit) 05e96c3] first commit1 files changed, 1 insertions(+), 0 deletions(-)create mode 100644 hello.txt(master)$ git showcommit 05e96c39452126e9310e84203af72f141c37a493Author: Habeeb Rahman <>Date: Tue Jun 18 13:46:35 2013 +0530first commitdiff --git a/hello.txt b/hello.txtnew file mode 100644index 0000000..557db03--- /dev/null+++ b/hello.txt@@ -0,0 +1 @@+Hello World
  14. 14. git diffgit diff: Show differences between your working directory and theindex.git diff –cached: Show differences between the index and themost recent commit.git diff HEAD: Show the differences between your workingdirectory and the most recent commit.
  15. 15. git commit --amendyou commit and then realize you forgot to stage the changes in a fileyou wanted to add to this commit:$ git commit -m initial commit$ git add forgotten_file$ git commit --amend
  16. 16. branchcreate a new branch:(master)$ git checkout -b dev_featureSwitched to a new branch dev_featureswitch 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"
  17. 17. branchdelete a branch$git branch -d dev_new_branchshow all local branches:$git branchshow all local and remote branches:$git branch -a
  18. 18. branch & merge
  19. 19. mergemerge dev_feature branch into master:(dev_feature)$ git checkout masterSwitched to branch masterfind out whats 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-forwardfeature.txt | 1 +1 files changed, 1 insertions(+), 0 deletions(-)create mode 100644 feature.txt
  20. 20. git blame(master)$ git blame feature.txt70c1e306 (Habeeb Rahman 2013-06-18 15:50:47 +0530 1) newfeature added
  21. 21. git log(master)$ git logcommit 70c1e3069a68877fca9680b045185288c5201a46Author: Habeeb Rahman <>Date: Tue Jun 18 15:50:47 2013 +0530featurecommit 05e96c39452126e9310e84203af72f141c37a493Author: Habeeb Rahman <>Date: Tue Jun 18 13:46:35 2013 +0530first commit(master)$ git log --oneline70c1e30 feature05e96c3 first commit
  22. 22. git grep(master)$ git grep hellohello.txt:hello worldnew.txt:hello everyone
  23. 23. git cloneLocal:git clone /path/to/repositoryRemote:git clone git://
  24. 24. git helpdisplay help information about git$ git help help$ git help grep$ git help reset
  25. 25. further reading