Git Crash Course

download Git Crash Course

of 57

  • date post

    28-Jan-2015
  • Category

    Software

  • view

    112
  • download

    1

Embed Size (px)

description

"Git Crash Course/Brown Bags" the basics of creating Git repositories, do versioning of files, branching and merging.

Transcript of Git Crash Course

  • 1. RACKSPACE HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Brown bag - Crash course From I cloned, to I push

2. RACKSPACE HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Agenda Presentation (20) o Basic commands o Branching and merging o Git repositories and sharing code Q&A (5) Quiz (5) 3. RACKSPACE HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Git setup $ git config --global user.name "FOO BAR" $ git config --global user.email foobar@acme.com 4. RACKSPACE HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk The very beginning $ mkdir ccbb-git $ cd ccbb-git $ ll total 0 drwxr-xr-x 2 simo6545 1604020879 68 Feb 1 09:01 ./ drwxr-xr-x 117 simo6545 1604020879 3978 Feb 1 09:01 ../ local directory 5. RACKSPACE HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Working directory $ git usage: git [--version] [--help] [-c name=value] [--exec-path[=]] [--html-path] [--man-path] [--info- path] [-p|--paginate|--no-pager] [--no-replace-objects] [--bare] [--git-dir=] [--work-tree=] [--namespace=] [] The most commonly used git commands are: add Add file contents to the index bisect Find by binary search the change that introduced a bug branch List, create, or delete branches ... 6. RACKSPACE HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Working directory - poking around $ echo 'The very beginning' > README $ git status fatal: Not a git repository (or any of the parent directories): .git $ ls -la total 8 drwxr-xr-x 3 simo6545 1604020879 102 Feb 1 09:28 . drwxr-xr-x 117 simo6545 1604020879 3978 Feb 1 09:01 .. -rw-r--r-- 1 simo6545 1604020879 19 Feb 1 09:28 README 7. RACKSPACE HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Working directory - create repository $ git init Initialized empty Git repository in /Users/simo6545/tmp/20140201-090152/.git/ $ ll total 8 drwxr-xr-x 4 simo6545 1604020879 136 Feb 1 09:38 ./ drwxr-xr-x 117 simo6545 1604020879 3978 Feb 1 09:01 ../ drwxr-xr-x 9 simo6545 1604020879 306 Feb 1 09:39 .git/ -rw-r--r-- 1 simo6545 1604020879 19 Feb 1 09:28 README working directory 8. RACKSPACE HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Working directory status $ git status # On branch master # # Initial commit # # Untracked files: # (use "git add ..." to include in what will be committed) # # README nothing added to commit but untracked files present (use "git add" to track) 9. RACKSPACE HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Staging area $ git status -s ?? README $ git add README $ git status -s A README stage changes 10. RACKSPACE HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Staging area $ echo 'This is the second line.' >> README $ git status -s AM README $ git diff diff --git a/README b/README index 939d82f..9e92fed 100644 --- a/README +++ b/README @@ -1 +1,2 @@ The very beginning +This is the second line. 11. RACKSPACE HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Staging area $ git add README $ git status -s A README Stage changes again: $ git diff 12. RACKSPACE HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Commit to Git repository $ git commit -m 'First commit' [master (root-commit) 7c23e33] First commit 1 file changed, 2 insertions(+) create mode 100644 README $ git log commit 7c23e33b09b4863dbf59dbaec7bb023f7ff15c70 Author: Simone Soldateschi Date: Sat Feb 1 10:10:48 2014 +0000 First commit 13. RACKSPACE HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Recap - The three states 14. RACKSPACE HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Basic commands 15. RACKSPACE HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Tagging $ git tag v0.1 $ git lg * 7c23e33 - (HEAD, tag: v0.1, master) First commit (63 minutes ago) $ echo 'Still working...' >> README $ git status -s M README $ git add README $ git status -s M README 16. RACKSPACE HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Tagging $ git commit -m 'Second commit' [master a0a8c4b] Second commit 1 file changed, 1 insertion(+) $ git status -s $ git lg * a0a8c4b - (HEAD, master) Second commit (6 seconds ago) * 7c23e33 - (tag: v0.1) First commit (67 minutes ago) $ git tag v0.2 $ git lg * a0a8c4b - (HEAD, tag: v0.2, master) Second commit (6 seconds ago) * 7c23e33 - (tag: v0.1) First commit (67 minutes ago) 17. RACKSPACE HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk File status lifecycle 18. RACKSPACE HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Agenda Presentation (20) o Basic commands o Branching and merging o Git repositories and sharing code Q&A (5) Quiz (5) 19. RACKSPACE HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Branching $ git init Initialized empty Git repository in /Users/simo6545/tmp/20140201-090152/.git/ $ echo 'The first line' > README $ git add README $ git commit -m 'C0' [master (root-commit) 38e3df8] C0 1 file changed, 1 insertion(+) create mode 100644 README $ echo 'The second line' >> README $ git add README $ git commit -m 'C1' [master 836e142] C1 1 file changed, 1 insertion(+) 20. RACKSPACE HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Branching 21. RACKSPACE HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Branching $ echo 'Experimental line' >> README $ git add README $ git commit -m "C2" [experiment 18c3f30] C2 1 file changed, 1 insertion(+) 22. RACKSPACE HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Branching 23. RACKSPACE HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Branching 24. RACKSPACE HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Branching 25. RACKSPACE HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Branching 26. RACKSPACE HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Branching 27. RACKSPACE HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Merging 28. RACKSPACE HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Merge conflict $ git merge experiment Auto-merging README CONFLICT (content): Merge conflict in README Automatic merge failed; fix conflicts and then commit the result. $ cat README The first line The second line > experiment 29. RACKSPACE HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Merge conflict $ cat README The first line The second line The third line Experimental line Another experimental line The last experimental line $ git add README $ git commit -m C6 30. RACKSPACE HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Rollback Current content of README: Look at repository logs: Rollback: 31. RACKSPACE HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Rollback How does README look like? What about repository logs? 32. RACKSPACE HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Checkout List branches (?!) Restore master 33. RACKSPACE HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Agenda Presentation (20) o Basic commands o Branching and merging o Git repositories and sharing code Q&A (5) Quiz (5) 34. RACKSPACE HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Git repos & sharing code 35. RACKSPACE HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Git repos & sharing code http://gitorious.org http://gna.org/projects/savane/ 36. RACKSPACE HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Git repos & sharing code remote clone pull push 37. RACKSPACE HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Remote repository 38. RACKSPACE HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Remote repository 39. RACKSPACE HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Remote repository $ git remote origin $ git remote -v origin git@github.com:siso/ccbbgit.git (fetch) origin git@github.com:siso/ccbbgit.git (push) 40. RACKSPACE HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Remote repository 41. RACKSPACE HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk pull do stuff push 42. RACKSPACE HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Remote repository - README.md $ cat > README.md master 45. RACKSPACE HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Remote repository 46. RACKSPACE HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk local actions and objects remote actions and objects 47. RACKSPACE HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk 48. RACKSPACE HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk A successful branching model 49. RACKSPACE HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Git aliases $ git config --global alias.b branch $ git config --global alias.lg log --graph --pretty=format:'%Cred%h%Creset - %C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit --date=relative $ git config --global alias.serve !git daemon --reuseaddr --verbose --base- path=. --export-all ./.git $ git config --global alias.st status st 50. RACKSPACE HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Agenda Presentation (20) o Basic commands o Branching and merging o Git repositories and sharing code Q&A (5) Quiz (5) 51. RACKSPACE HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk 52. RACKSPACE HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Agenda Presentation (20) o Basic commands o Branching and merging o Git repositories and sharing code Q&A (5) Quiz (5) 53. RACKSPACE HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Quiz 54. RACKSPACE HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Give your feedback! 55. RACKSPACE HOSTING | WWW.RACKSPACE.COMsimone.sol