Presentation on theme: "PicassoMonetMatejko + Canaletto Malczewski + Chelmonski Git Luca Milanesio Android programming Sang Shin The Productive Programmer Neal Ford The Power."— Presentation transcript:
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
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
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
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
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)
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 !
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
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 !
BORED of too much theory ?
Let’s experiment Git in action !
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)
LMIT Software Limited – Step 2 – Git identity Define your full name Define your Everything stored in.git/config
LMIT Software Limited – Step 3 – Add some files and commit Create some files Add to GIT (default = recursive) Commit
LMIT Software Limited – Step 4 – Inspect GIT log Get GIT history of commits Display changes
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
LMIT Software Limited – State 1. unstaged Create a new file Change an existing file Check status
LMIT Software Limited – State 2. staged Add the two files to staging area Check status
LMIT Software Limited – State 3. work directory clean Commit the staging area Check status
LMIT Software Limited – Display Git lifecycle Add another file and make some changes $ git gui
LMIT Software Limited – Stage with git gui Select files and chose “Stage to commit”
LMIT Software Limited – Commit with git gui Enter commit message and click “commit”
LMIT Software Limited – Git graph log with gitk
Playtime is over
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
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 !
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 !!!
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
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
LMIT Software Limited – Where are Git objects ? Git objects are in.git/objects SHA-1 identify directory / file
LMIT Software Limited – Curious about Git objects ? Git objects are compressed Use git show to display content
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
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.
LMIT Software Limited – How Git commits graph looks like ? Picture courtesy of ProGit.org Reference Commit Tree
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
LMIT Software Limited – Real-life Git branches Think I’m exaggerating ? Look at this example ( it’s real, swear ! )
Let’s practice on Git branches !
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
LMIT Software Limited – Creating branches Create branch create a new ref to current commit
LMIT Software Limited – Switching branch Use git checkout to switch branch Current displayed branch changed to experimental Note that HEAD points to experimental
LMIT Software Limited – Commit on branch Add a new commit to experimental branch See the new branch graph ( gitk )
LMIT Software Limited – Merge When experiments are completed … merge back ! – Checkout master – Merge experimental
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
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
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
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
LMIT Software Limited – Merge alternatives: rebase Picture courtesy of ProGit.org
LMIT Software Limited – Git rebase in action Let’s diverge again between master and experimental Magic ! … rebase flattens the branching history
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 !
LMIT Software Limited – Merge alternatives: cherry-pick Get individual commit IDs Apply individual changes to another branch
LMIT Software Limited – Git branch graph after cherry-pick Individual commit has been copied from tesla-test Both branches are kept
Too easy ? … let’s create some conflict !
LMIT Software Limited – Merge conflict Same file changed, same range, two different branches
LMIT Software Limited – Resolving conflict Get list of conflicts with git status Display and edit conflicted file
LMIT Software Limited – Completing merge Add edited file to stage Commit and finalise the merged commit … wasn’t that scary isn’t it ?
LMIT Software Limited – Rebase / cherry-pick conflict Same file changed, same range, two different branches
LMIT Software Limited – Don’t panic … unnamed branch Check in which branch you are Check files in conflict
LMIT Software Limited – Resolve conflict and continue rebase Resolve conflicts Continue rebase
Got lost with commands, merge and conflicts ?
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
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 !!!!!
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)
LMIT Software Limited – Amend last commit Let’s display the last commit on master
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 …
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
LMIT Software Limited – Hard reset Remove commit and all the changes associated Commit is lost FOREVER : there is no way to restore the data
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)
LMIT Software Limited – Display last commit Let’s display the last commit changes on master
LMIT Software Limited – Now: how to revert the revert ? Reverted commit is a commit Use reset to eliminate the revert operation
Working with Tags
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)
LMIT Software Limited – Lightweight tags Let’s create a lightweight tag … that’s easier to remember than b7dbbe69f0be…. !
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
LMIT Software Limited – Create GPG Key pair
LMIT Software Limited – Create annotated tag Let’s create a fully annotated and signed tag Tags are just Git references
Git remote management
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
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
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
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
Git collaboration: anarchy
LMIT Software Limited – Everybody fetch/pull from each other AnnaJohnCathyLinusLukePeter Nobody pushes: everybody fetch or pull Every Git repository has the same importance
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
Git collaboration: dictator and lieutenants
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
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
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
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 ?
LMIT Software Limited – Git branching model Picture courtesy of ProGit.org
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
LMIT Software Limited – Topic branches example Developer A starts working on topic-1 Developer B starts working on topic-2
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
LMIT Software Limited – Code-review: merge topic-2 Repeat the same with topic-2
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
LMIT Software Limited – Further reading and references Further reading ProGit: Git cheat sheets: Git Services: github: GitEnterprise:
You resisted 3h … YEAH ! Thank you for your patience,
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