Presentation is loading. Please wait.

Presentation is loading. Please wait.

PicassoMonetMatejko + Canaletto Malczewski + Chelmonski Git Luca Milanesio Android programming Sang Shin The Productive Programmer Neal Ford The Power.

Similar presentations


Presentation on theme: "PicassoMonetMatejko + Canaletto Malczewski + Chelmonski Git Luca Milanesio Android programming Sang Shin The Productive Programmer Neal Ford The Power."— Presentation transcript:

1 PicassoMonetMatejko + Canaletto Malczewski + Chelmonski Git Luca Milanesio Android programming Sang Shin The Productive Programmer Neal Ford The Power of Retrospection Linda Rising Introduction to Scala Hubert Plociniczak Main sponsor

2 LMIT Software Limited – Agenda SCM and Git Concepts Git quick start Branching and merging Resolving conflicts Reverting changes Working with tags Git remotes Git on the server Git peer-to-peer Git democracy

3 LMIT Software Limited – Who’s that guy ? Luca Milanesio LMIT Limited – Director / co-founder of GitEnterprise.com Jenkins (formerly Hudson) contributor since 2007 founder of hudson-mobi.comhudson-mobi.com Over 18 years of experience in Software and Services Development and Application Lifecycle Worked for major UK, EU and US Customers – Banking, Retailers, Industry, Finance, Telecoms, Utilities, Government Git enthusiast since 2009 and innovator in Vodafone Group Services Ltd

4 LMIT Software Limited – About SCM … remember ? Picture courtesy of globalnerdy.com - All rights kindly reserved SCM = Source Code Management Multiple revisions of files Commit and rollback changes Define change-sets Tag important releases Manage branches of development Integrate the work of multiple teams together … and much more

5 LMIT Software Limited – Brief history of OpenSource SCMs Local SCMs (versions kept on local filesystem) SCCS (1972) … I was not yet born, don’t remember  RCS (1982) the most widely used on Unix Server-based SCMs (central repository server) CVS (1990) first widely used SCM server Subversion (2000) first widely Internet SCM … and then let’s to go distributed … DCVS (2002) who has ever used it ? Mercurial and Git (2005)

6 LMIT Software Limited – Centralised vs. distributed ? How many of you are using central repositories ? CVS-boys … raise your hands ! SVN-guys … it’s your turn ! How many are for distributed repositories ? Mercurial-scientists... raise your hands ! Git-explorers … brave men !

7 LMIT Software Limited – Who’s right ? Central SCM Unique “source of truth” Central back-up Seamless alignment for all developers Security and access control Distributed SCM Community code-base No single-point-of-failure Peer-to-peer alignment Continuous branching and merging

8 LMIT Software Limited – Why GIT ? It’s all about BitKeeper fault: they broke up with Linus Torvalds … and I’m not kidding Story: Linux Kernel SCM: BitKeeper Apr 2005 – Linus writes PERL scripts for Linux Kernel SCM Jul 2005 … Git 0.99 is out ! Git principles: Allow the BitKeeper SCM workflow Use CVS as the “not-to-do” example Check and prevent corruption Make it FFF … FAST FAST FAST !

9 BORED of too much theory ?

10 Let’s experiment Git in action !

11 LMIT Software Limited – Git installation (Ver. >=1.6) Linux (Git favourite of course !) – Ubuntu: sudo apt-get install git-core – other Linux ? … best from source code Mac OSX – Windows – (sucks … but it’s your fault not using Unix) – Cygwin HIGHLY RECOMMENDED (mandatory IMHO)

12 LMIT Software Limited – Step 1 – Git repository  create project  cd into project  $ git init

13 LMIT Software Limited – Step 2 – Git identity  Define your full name  Define your  Everything stored in.git/config

14 LMIT Software Limited – Step 3 – Add some files and commit  Create some files  Add to GIT (default = recursive)  Commit

15 LMIT Software Limited – Step 4 – Inspect GIT log  Get GIT history of commits  Display changes

16 LMIT Software Limited – Too simple ? … let’s add some states Three states of Git files 1. Unstaged2. Staged3. Clean Picture courtesy of ProGit.org git add git commit

17 LMIT Software Limited – State 1. unstaged Create a new file Change an existing file Check status

18 LMIT Software Limited – State 2. staged Add the two files to staging area Check status

19 LMIT Software Limited – State 3. work directory clean Commit the staging area Check status

20 LMIT Software Limited – Display Git lifecycle Add another file and make some changes $ git gui

21 LMIT Software Limited – Stage with git gui Select files and chose “Stage to commit”

22 LMIT Software Limited – Commit with git gui Enter commit message and click “commit”

23 LMIT Software Limited – Git graph log with gitk

24 Playtime is over 

25 LMIT Software Limited – Git stores the whole file Git is different from SVN: no diffs, just whole files Git stores changed files between snapshots (BitKeeper docet) Picture courtesy of ProGit.org

26 LMIT Software Limited – Git object types: blobs Git stores all files (and their versions) as objects (blobs) Each object has a SHA bit identifier SHA-1 provides: – Unique Global ID – Integrity check Example: – File content: “ You're GIT too ” – SHA-1: bbecf72783dfba9e0243e13dbb5fb04ed39ed4e4 (Hex) Track content (not files) Automatically detect renames … cool !

27 LMIT Software Limited – SHA-1 ? WTF … Why Linus Torvalds has chosen SHA-1 hashing ? – Need for track content globally – SHA-1 collision probability is 1/2 51 What happens if two files have same SHA-1 ? – BOOM ! What is the probability of it ? – World’s population (7 BN people) sharing files of 10 times Linux Kernel Possible ? More likely to be hit by a 15 KM asteroid NOW !!!

28 LMIT Software Limited – Git object types: commits and trees Git tree identifies a snapshot (set of files) Git commit identifies – Author / Committer – Commit message – Timestamp – Tree Picture courtesy of ProGit.org

29 LMIT Software Limited – Git history: graph of commits Every commit points to its predecessor Series of commits make Git repository history Picture courtesy of ProGit.org

30 LMIT Software Limited – Where are Git objects ? Git objects are in.git/objects SHA-1 identify directory / file

31 LMIT Software Limited – Curious about Git objects ? Git objects are compressed Use git show to display content

32 LMIT Software Limited – Getting lost ? How to remember SHA-1 hashing codes ? How Git stores the “pointers” to Commit graph ? Git references are the solution ! – Head of the Git history – Intermediate tags – Branch points – Relative points

33 LMIT Software Limited – Git references References: “labels” for Git SHA-1 commit IDs Stored as files under.git/refs Reference types: – Tags – Heads (branches) HEAD is a special ref: always points to head of current branch.

34 LMIT Software Limited – How Git commits graph looks like ? Picture courtesy of ProGit.org Reference Commit Tree

35 LMIT Software Limited – What is a branch for Git ? Git named branch = reference to a commit ID (head of branch) Git supports “network” of commits, with named and unnamed branches … don’t know why Git reminds me some “underground” branches

36 LMIT Software Limited – Real-life Git branches Think I’m exaggerating ? Look at this example ( it’s real, swear ! )

37 Let’s practice on Git branches !

38 LMIT Software Limited – Wear “life jacket” first Get Git bash extensions source git/contrib/completion/git-completion.bash Redefine prompt export PS1='\W$(__git_ps1 " (%s)") \$ ’... and your current branch is visible on your prompt: you will not get lost

39 LMIT Software Limited – Creating branches Create branch  create a new ref to current commit

40 LMIT Software Limited – Switching branch Use git checkout to switch branch Current displayed branch changed to experimental Note that HEAD points to experimental

41 LMIT Software Limited – Commit on branch Add a new commit to experimental branch See the new branch graph ( gitk )

42 LMIT Software Limited – Merge When experiments are completed … merge back ! – Checkout master – Merge experimental

43 LMIT Software Limited – Git graph after merge Let’s have a look on the result with gitk Merge-type applied: Fast-forward (move refs in history) Branch has been “flattened” Experimental just another ref to master

44 LMIT Software Limited – Git recursive-merge Let’s create some divergence Changes on both master and experimental Fast-forward merge = move branch ref to another commit ID

45 LMIT Software Limited – Git diverging branches Use gitk --all to display all branches NOTE: no args displays just current branch experimental is really diverging from master

46 LMIT Software Limited – Git recursive merge Let’s merge again with master This is a real merge folks ! NOTE: Merge is a Git commit: you can associate a comment, or revert it later ! Don’t be scared by Git-managed merge

47 LMIT Software Limited – Merge alternatives: rebase Picture courtesy of ProGit.org

48 LMIT Software Limited – Git rebase in action Let’s diverge again between master and experimental Magic ! … rebase flattens the branching history

49 LMIT Software Limited – Git graph after rebase Experimental is no more a diverging branch NOTE: Marconi’s test is on “unnamed branch” and experimental branch history has changed !

50 LMIT Software Limited – Merge alternatives: squash C1C2C3C4 C5C6 origin mywork C1C2C3C4C3C4 origin mywork C3’+C4’

51 LMIT Software Limited – Git squash in action Get branch changes but do not join them git merge –squash experimental  commit

52 LMIT Software Limited – Git branch graph after squash Branches are still diverging Get all the branch changes in a single commit (squash changes together)

53 LMIT Software Limited – Merge alternatives: cherry-pick C1C2C3C4 C5C6 origin mywork C1C2C3C4C5C6 origin mywork C6’

54 LMIT Software Limited – Merge alternatives: cherry-pick Get individual commit IDs Apply individual changes to another branch

55 LMIT Software Limited – Git branch graph after cherry-pick Individual commit has been copied from tesla-test Both branches are kept

56 Too easy ? … let’s create some conflict !

57 LMIT Software Limited – Merge conflict Same file changed, same range, two different branches

58 LMIT Software Limited – Resolving conflict Get list of conflicts with git status Display and edit conflicted file

59 LMIT Software Limited – Completing merge Add edited file to stage Commit and finalise the merged commit … wasn’t that scary isn’t it ?

60 LMIT Software Limited – Rebase / cherry-pick conflict Same file changed, same range, two different branches

61 LMIT Software Limited – Don’t panic … unnamed branch Check in which branch you are Check files in conflict

62 LMIT Software Limited – Resolve conflict and continue rebase Resolve conflicts Continue rebase

63 Got lost with commands, merge and conflicts ?

64 LMIT Software Limited – Merge recap Type of mergeConflict whenBranch results git mergeSame file, same rangeBranches merged (keep branch history) git rebaseSame file, same rangeFast-forward, flatten history git merge --squashSame file, same rangeKeep branches, apply changes git cherry-pickSame file, same rangeKeep branches, apply individual commits

65 Reverting changes

66 LMIT Software Limited – Git is powerful and dangerous Git has full control on history – Amend existing commits – Remove commits – Revert changes Be careful: you could destroy your history ! Be even more careful: history revert is unrecoverable SCARY !!!!!

67 LMIT Software Limited – Change existing commits Git commit support the “amend” option to overwrite committed data What can be amended – File changes – Author / comment – Date The original commit will disappear : amend is NOT revertible (but just amended again)

68 LMIT Software Limited – Amend last commit Let’s display the last commit on master

69 LMIT Software Limited – Amend last commit Let’s change commit content

70 LMIT Software Limited – Git reset: back to the past Git reset allows to: – Put committed data back to the working dir  soft reset – Remove completely committed data  hard reset Git reset is NOT revertible You want to reset ? – Do you really need it ? – Do you really want it ? – What do you want to achieve ? – … and then think again …

71 LMIT Software Limited – Soft reset Remove the last commit and put changes back to workdir Hint: master~1 = reference to “one commit before master head” Commit is lost, but you still have the changes in workdir

72 LMIT Software Limited – Hard reset Remove commit and all the changes associated Commit is lost FOREVER : there is no way to restore the data

73 LMIT Software Limited – Git revert Git revert allows to: – Revert the changes and to workdir – Revert the changes and create a “reverted commit” Git revert is revertible Revert = negative commit (eliminates effect of reverted commit)

74 LMIT Software Limited – Display last commit Let’s display the last commit changes on master

75 LMIT Software Limited – Create reverted commit Let’s revert last commit

76 LMIT Software Limited – Now: how to revert the revert ? Reverted commit is a commit Use reset to eliminate the revert operation

77 Working with Tags

78 LMIT Software Limited – Importance of Git tags Why using tags ? … yeah, you know it Why is MORE IMPORTANT in Git than in SVN ? – Git commit IDs is SHA-1 hashing (WTF – Tags = reference to a commit (zero payload) Type of Git tags – Lightweight tags (simple Git ref to a commit ID) – Annotated tags (author, description, signature)

79 LMIT Software Limited – Lightweight tags Let’s create a lightweight tag … that’s easier to remember than b7dbbe69f0be…. !

80 LMIT Software Limited – Fully annotate tags Fully annotated tags contains meta-data: – Timestamp – Author name and – Description – Commit ID – GPG Digital Signature Create your private GPG Key-pair first – GPG Public Key identify your user – GPG Private Key is used to sign content (tags, commits) – Exchange GPG Public Key with your peers

81 LMIT Software Limited – Create GPG Key pair

82 LMIT Software Limited – Create annotated tag Let’s create a fully annotated and signed tag Tags are just Git references

83 Git remote management

84 LMIT Software Limited – Git nature: peer-to-peer distributed Git designed to be distributed – Global unique IDs for files and commits (SHA-1) – Completely disconnected operations – Rich set of merging capabilities – Compression and integrity check Natural way of using it is peer-to-peer … the Linus way, yeah

85 LMIT Software Limited – Remote Git repositories Points to other’s people repository – Remote Git servers / location – Remote Git branches Example: clone GIT source code repository via “remote” – git clone git://git.kernel.org/pub/scm/git/git.git

86 LMIT Software Limited – Inspecting remote pointers List of remote Git repositories Name “origin” refers to remote Git repository List of remote Git branches

87 LMIT Software Limited – Push changes to remote Git repository Add pointer to remote Git repository Push all local branches to remote Git repository

88 LMIT Software Limited – Getting remote Git repository updates 1.Fetching remote changes with git fetch 2.Merge (or rebase) changes

89 LMIT Software Limited – Getting changes: shortcuts 1.Use git pull for merging with remote changes git pull = git fetch + git merge … beaware of the branches merge mess ! 2.Use git fetch + git rebase with a macro: git update update = !sh -c 'git stash clear && git stash && git fetch origin && git rebase origin/master && git stash pop’ git update = git fetch + git rebase … flat and clean history … seems like SVN isn’t it ?

90 LMIT Software Limited – Git repositories (local/remote) recap

91 Choosing your Git Server

92 LMIT Software Limited – Public Git Server: github Many choices … but github is the best ! 1.Create your SSH Key-pair ssh-keygen -t rsa -b Create your free acount on: https://github.com/signup/free https://github.com/signup/free 3.Create your repository on: https://github.com/repositories/new https://github.com/repositories/new 4.Add your remote git remote add origin

93 LMIT Software Limited – Private Git Server: GitEnterprise Many choices … but this is the best for FREE 1.Create your SSH Key-pair (optional: you can use HTTP/basic auth, firewall frendly ) ssh-keygen -t rsa -b Create your free acount on: https://gitent-scm.com/gitent/users/SignUp.git https://gitent-scm.com/gitent/users/SignUp.git 3.Create your repository on: https://gitent-scm.com/gitent/repository/RepositoryCreation.git https://gitent-scm.com/gitent/repository/RepositoryCreation.git 4.Add your remote git remote add origin scm.com/git/gitentdevelopment/33degree

94 LMIT Software Limited – 3 rd choice: make your own ! Installed on your network, running on your hardware NOTE: make daily backups … GIT is dangerous ! Gitosis (http://eagain.net/gitweb/?p=gitosis.git)http://eagain.net/gitweb/?p=gitosis.git – Users / Groups / Keys – Repository management – Everything managed with Git Management Repository Gerrit (http://code.google.com/p/gerrit/)http://code.google.com/p/gerrit/ – Full Web-based Interface – Users / Groups integrated with LDAP, OpenID, … – Full repository and security management – Full code-review lifecycle management

95 Git collaboration: anarchy

96 LMIT Software Limited – Everybody fetch/pull from each other AnnaJohnCathyLinusLukePeter Nobody pushes: everybody fetch or pull Every Git repository has the same importance

97 LMIT Software Limited – How does it work ? Run your own Git server with git daemon Others can clone and fetch from your repository You see them fetching

98 Git collaboration: dictator and lieutenants

99 LMIT Software Limited – Developers fetch/pull, dictator pushes Developers pull, Lieutenants integrate Dictator get integration branches together: he is the only one that PUSH to Git git push Picture courtesy of ProGit.org

100 LMIT Software Limited – GitHub variant git push Developers pull from “blessed” and have their own public Git Integration manager is the Dictator Revolution allowed : developer nominates himself “new dictator” Picture courtesy of ProGit.org

101 Git Democracy

102 LMIT Software Limited – Unique central repository Everybody can push / pull from shared Git Repository Central repository dies  elections of new repository Picture courtesy of ProGit.org

103 LMIT Software Limited – Back to centralisation ? WTF ? Does it seems like SVN ? … much more guys Git Democracy vs. SVN – Horizontal collaboration between developers (P2P) – Continuous branching / merging – “promotions” of changes through voting (Gerrit model) – Control over integration / release Does it seems like Git is mature for the Enterprise ?

104 LMIT Software Limited – Git branching model Picture courtesy of ProGit.org

105 LMIT Software Limited – Working with topic branches Developers work on topics Code-review / votes promote them to master Topics branches removed after merge NOTE: better rebase than merge Picture courtesy of ProGit.org

106 LMIT Software Limited – Topic branches example Developer A starts working on topic-1 Developer B starts working on topic-2

107 LMIT Software Limited – Code-review: merge topic-1 Get topic-1 code and code-review on integration branch Everything’s fine: commit the merge and remove topic-1

108 LMIT Software Limited – Code-review: merge topic-2 Repeat the same with topic-2

109 LMIT Software Limited – Release manager: merge integration Release manager decides about releasing integration branch NOTE: No conflicts are generated  all merges are from integration branch

110 LMIT Software Limited – Further reading and references Further reading  ProGit:  Git cheat sheets: Git Services:  github:  GitEnterprise:

111 You resisted 3h … YEAH ! Thank you for your patience,

112 PicassoMatejko + CanalettoMalczewski + Chelmonski BOF: Hack your company Jakub Nabrdalik BOF: Web framework shootout Błażej Bucko, Tomasz Dziurko, Wojciech Erbetowski, Łukasz Kuczera, Paweł Szulc BOF: Future of Java EE Alexis Moussine-Pouchkine BOF: Those broken, broken class loaders Jevgeni Kabanov Main sponsor


Download ppt "PicassoMonetMatejko + Canaletto Malczewski + Chelmonski Git Luca Milanesio Android programming Sang Shin The Productive Programmer Neal Ford The Power."

Similar presentations


Ads by Google