SlideShare a Scribd company logo
1 of 66
itcampro@ itcamp13# Premium conference on Microsoft technologies
Git crash course for Visual
Studio devs
Alessandro Pilotti
Cloudbase Solutions
MVP ASP.Net / IIS
@alexpilotti
itcampro@ itcamp13# Premium conference on Microsoft technologies
Development &
MobileHuge thanks to our sponsors!
itcampro@ itcamp13# Premium conference on Microsoft technologies
Development &
Mobile
• Why Git?
• Basics
• Visual Studio integration
• Remote repositories
• Branching
• Merging and rebasing
• Forks and github, bitbucket, etc
• Continuous deployment
• Gerrit
• Azure support
Agenda
itcampro@ itcamp13# Premium conference on Microsoft technologies
Development &
Mobile
• Why do we need an ENTIRE session on a VCS
instead of talking about code? 
• Previous VCS are so simple:
– CVS
– Subversion
– Sourcesafe (D’oh)
• In short, it’s because there’s way more than
the usual commit / checkout thing 
Why Git?
itcampro@ itcamp13# Premium conference on Microsoft technologies
Development &
Mobile
• Developed initially by Linus Torvalds in 2005
– Used for the Linux Kernel
– GPLv2
– Multiplatform (Linux, Windows, OSX, FreeBSD)
• Some design goals:
– Fast and efficient
– Support for non linear development
– Distributed
– Easy publishing
– Garbage collection
Git
itcampro@ itcamp13# Premium conference on Microsoft technologies
Development &
Mobile
• In most cases, you just start work on a
project using it 
– In my case, OpenStack
• Most OSS projects are hosted on github
– CodePlex supports Git as well
• Ease to branch, merge, fork
• Once you start using it, it’s hard to go back
Why should I use it?
itcampro@ itcamp13# Premium conference on Microsoft technologies
Development &
Mobile
• http://msysgit.github.io/
– Command line
• http://windows.github.com/
• Visual Studio 2012 Update 2
• NetBeans
• Eclipse
• TortoiseGit
• etc
Windows clients
itcampro@ itcamp13# Premium conference on Microsoft technologies
Development &
Mobile
• A Git repository is a directory tree containing
your project(s)
– A hidden directory “.git” contains all the Git stuff
• Start a repo from scratch:
– git init
• Cloned from an existing repo:
– git clone
https://github.com/cloudbase/cloudbase-init
Basics
itcampro@ itcamp13# Premium conference on Microsoft technologies
Development &
Mobile
• Files are either:
– Staged (git knows about them)
– Untracked (git doesn’t care about them)
• To stage a file / directory:
– git add path
• To unstage and delete a file:
– git rm path
• To unstage w/o deleting it:
– git rm –cached path
Staging files
itcampro@ itcamp13# Premium conference on Microsoft technologies
Development &
Mobile
• As simple as:
– git commit –a –m “Don’t forget the commit
msg”
• To commit a file:
– git commit -m msg path
• Being a distributed VCS, a commit is only
local
• Do small commits, atomic and cohesive
– With a clear commit message
– A VCS is not a backup tool 
Commit
itcampro@ itcamp13# Premium conference on Microsoft technologies
Development &
Mobile
• You can look at the history for the current
branch with a simple:
– git log
– git log --pretty=oneline
• To see your staged (uncommitted) changes:
– diff format
– git diff
• To see the differences between two commits:
– git diff commit1 commit2
Git log, show and diff
itcampro@ itcamp13# Premium conference on Microsoft technologies
Development &
Mobile
• With checkout you can get a file or a working
copy of your repository:
– E.g.: to undo your work to the latest commit:
– git checkout (entire repo)
– git checkout file (single file only)
• To checkout a file to a previous version:
– git checkout commitref file
– E.g.: to get the previous version:
• git checkout HEAD^ file
• git checkout HEAD^
checkout
itcampro@ itcamp13# Premium conference on Microsoft technologies
Development &
Mobile
• git config --global user.name ”My Name”
• git config --global user.email myuser@mydomain.com
• git config --global color.ui true
• git config --global core.editor notepad++
– Note: add the editor to your path first (elevated console):
• SETX PATH “%PATH%;%ProgramFiles% (x86)Notepad++” /M
– Even better, getting used to vi is not so terrible 
• git config --global core.autocrlf true
– Values: true, input, false
– Set true if you work on multiplatform projects
– See .gitattributes later for this as well
Global settings
itcampro@ itcamp13# Premium conference on Microsoft technologies
Development &
MobileGit and Visual Studio 2012
itcampro@ itcamp13# Premium conference on Microsoft technologies
Development &
Mobile
• VS 2012 Update 2 required
• Install Visual Studio Tools for Git
• Tools -> Options -> Source Control
– Choose “Microsoft Git provider”
• Open “Team Explorer”
– View -> Team Explorer
• You can use also regular git commands in
– Package Manager Console
Git and Visual Studio 2012
itcampro@ itcamp13# Premium conference on Microsoft technologies
Development &
Mobile
• Connect to Team Projects (socket icon)
– Clone
– Set the remote repo URL
– Specify a local path
VS 2012 Clone a repo
itcampro@ itcamp13# Premium conference on Microsoft technologies
Development &
Mobile
• RC available now
• http://blogs.msdn.com/b/visualstudioalm/arc
hive/2013/05/07/release-candidate-to-visual-
studio-update-3-now-available.aspx
• Bug fixes
• Git TFS continuous integration support
VS 2012 Update 3
itcampro@ itcamp13# Premium conference on Microsoft technologies
Development &
MobileVS2012 U3 Git
itcampro@ itcamp13# Premium conference on Microsoft technologies
Development &
MobileTFS + Git
TFS supports GIT natively! http://bit.ly/Z1RkcV
Signup for a free account here:
https://tfs.app.visualstudio.com/_account/Signu
p
itcampro@ itcamp13# Premium conference on Microsoft technologies
VS2012 GIT DEMO
itcampro@ itcamp13# Premium conference on Microsoft technologies
Development &
Mobile
• git contains all the info related to your repo
in “.git/”
• Your files (working copy), are simply a human
readable copy of the files 
– Bare repositories have no working copy
• The Index contains info about staged files
• File contents are stored into blobs
• Other objects include trees (the filesystem
refresentation) and commits
• Every object is identified with a SHA1 hash
A bit of internals
itcampro@ itcamp13# Premium conference on Microsoft technologies
Development &
Mobile
• You can refer to commits with their SHA1
hash or with a shorter unique prefix, e.g.:
– git log e46bf2165f29f579051b8e12ebe63e5512205610
– git log e46bf2
• Or you can refer to a commit using a
reference:
– every branch has a “head” identifying the last
commit
• git checkout branchname
Refs
itcampro@ itcamp13# Premium conference on Microsoft technologies
Development &
Mobile
• HEAD is a special symbolic link pointing to the
head of the current branch
• You can do some “arithmetic” with refs:
– ^ points to the previous commit
– ~n points to the nth previous commit
– HEAD^^^ the 3rd commit before HEAD
– HEAD~3 (same as the above example)
• Note: use (quotes) “HEAD^” in the Windows
cmd prompt
Refs
itcampro@ itcamp13# Premium conference on Microsoft technologies
Development &
Mobile
• A tag is simply a friendly name for a commit
– git tag v1.0 HEAD
• Annotated tags are stored as full objects:
– git tag –a v1.0 –m “Version 1.0” HEAD
• Don’t confuse tags with a branches
Tags
itcampro@ itcamp13# Premium conference on Microsoft technologies
Development &
Mobile
• Git is a distributed VCS
• You can “sync” your local copy with remote
copies anytime, by either “pull” or “push”
changes
• Git has no concept of a “server”
– Repos form a peer network
• It’s useful anyway to elect an “authoritative”
repository. E.g.:
– A repo on github, bitbucket, etc
– The project lead developer’s repo
Remote repositories
itcampro@ itcamp13# Premium conference on Microsoft technologies
Development &
Mobile
• A remote is simple a name and an url
• List remotes:
– git remote
• Add a remote:
– git add origin https://github.com/openstack/nova.git
• Note: this will track all remote branches, use –t <branchname> to
limit
• Protocols to access the remote repo can be:
– Local filesystem, HTTP/HTTPS, git, rsync
– Local fileystem on Windows:
• file:///c/your/path/repo.git
Configuring remotes
itcampro@ itcamp13# Premium conference on Microsoft technologies
Development &
Mobile
• Remove a remote:
– git remote rm name
• Changing a remote url is a frequent
operation:
– git remote set-url <newurl> <remote_name>
• Cleaning stale remote tracking branches
– git remote prune <remote_name>
Configuring remotes
itcampro@ itcamp13# Premium conference on Microsoft technologies
Development &
Mobile
• A bare repository doesn’t have a working
copy of your content
• Use it when you create an authoritative
“server” repo
• By convention bare repo folder names end it
“.git” e.g.: “myrepo.git”
• git init --bare
Bare repositories
itcampro@ itcamp13# Premium conference on Microsoft technologies
Development &
Mobile
• A typical operation consists in cloning a
remote repository (will set the proper remote
as well):
– git clone <url>
• To update a local repository with remote
commits:
– git pull
• This is a shortcut for git fetch and git merge
FETCH_HEAD
Clone / pull
itcampro@ itcamp13# Premium conference on Microsoft technologies
Development &
Mobile
• Updating a remote repository consists in:
– git push <remote> <branch>
– git push origin master
• Note: you must first make sure that you
pulled all the remote commits first!
• More on merging / rebasing later!
Push
itcampro@ itcamp13# Premium conference on Microsoft technologies
Development &
Mobile
• Git was created to make branching and
merging as easy as possible.
• “master” is the default branch
• From an application lifecycle standpoint we
can define two types of branches:
– Long lived
• Typically major releases
– Short lived
• Bug fixes, dev experiments, etc
• Git makes no difference of course
Branches
itcampro@ itcamp13# Premium conference on Microsoft technologies
Development &
Mobile
• Creating a branch is simply:
– git chekout –b name
– Shortcut for git branch name and git checkout name
• Switch to a different branch:
– git checkout name
– This will also change the working directory contents to reflect
the branch commits!!
• To list existing branches:
– git branch
– The active branch is marked with “*”
• To remove a branch:
– git branch –d name
Branches
itcampro@ itcamp13# Premium conference on Microsoft technologies
Development &
MobileHow does it look like?
A B
C
Dmaster
new-feature
E
F
experiment
master commits: A, B, D
new-feature commits: A, B, C, E
experiment commits : A, B, C, E, F
itcampro@ itcamp13# Premium conference on Microsoft technologies
Development &
Mobile
• In most cases at some point you’d like to merge
the content of a branch into another
• For example, you develop a new feature and
once it’s done tested and reviewed you want to
merge it in the master branch
• git-merge merges a branch into the current one:
– git checkout master
– git merge new-feature
Merge
itcampro@ itcamp13# Premium conference on Microsoft technologies
Development &
MobileHere’s how a merge looks like
A B
C
Dmaster
new-feature
E
F
experiment
G
master commits: A, B, D, C, E, G
itcampro@ itcamp13# Premium conference on Microsoft technologies
Development &
Mobile
• What happens when the same file has been
changed in two branches?
• Git is very smart in applying different commit
patches to the same source when lines do
not overlap (e.g. 2 different methods)
• But sometimes you just have to handle
conflicts, it’s a hard life 
Conflicts
itcampro@ itcamp13# Premium conference on Microsoft technologies
Development &
Mobile
git merge branch_name
CONFLICT (content): Merge conflict in test.txt
Automatic merge failed; fix conflicts and then
commit the result.
D’oh!
Edit the conflicting files…
git add files
git commit -a
Conflicts
itcampro@ itcamp13# Premium conference on Microsoft technologies
Development &
Mobile
• You can also rollback the merge with:
– git merge –abort
• A merge happens also when you pull a remote branch
– The resolution process is the same
• Once the merge succeeds, you can delete the merged
branch if you don’t need it anymore
• You can also keep on working on the merged branch and
merge it again later
• When you merge a branch w/o conflicts (fast-forwarding)
by default a merge commit is not created. This can be
changed with git merge –no-ff etc
Merge notes
itcampro@ itcamp13# Premium conference on Microsoft technologies
Development &
Mobile
• Rebasing a branch consists in taking the
commits of another branch and applying
them on the current branch before any
commit added to the current branch.
• Typically this is used to bring a local branch
up to date with remote commits
• Merge vs rebase can create a bit of confusion
to users
Rebase
itcampro@ itcamp13# Premium conference on Microsoft technologies
Development &
MobileRebase example
A B
C
Dmaster
new-feature
E
F
git checkout new-feature
git rebase master
Note: rebased commits have a new hash!
itcampro@ itcamp13# Premium conference on Microsoft technologies
Development &
Mobile
CONFLICT (content): Merge conflict in test3.txt
Failed to merge in the changes.
Patch failed at 0002 asdasdd
The copy of the patch that failed is found in:
/Users/anorex/Downloads/testgit/.git/rebase-apply/patch
When you have resolved this problem, run
"git rebase --continue".
If you prefer to skip this patch, run
"git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase -
-abort".
Rebase conflicts
• Similar to resolving a merge
itcampro@ itcamp13# Premium conference on Microsoft technologies
Development &
Mobile
• What if you just one to pick a single commit
from another branch without having to
merge / rebase the entire branch?
• E.g. backporting a bug fix from v1.2 to v1.1
• git cherry-pick commit1
• git cherry-pick start..end
Cherry picking
itcampro@ itcamp13# Premium conference on Microsoft technologies
Development &
MobileCherry-pick example
A B
C
Dmaster
new-feature
E
F
D
’
git checkout new-feature
git cherry-pick D
Note: cherry-picked commits have a new hash!
itcampro@ itcamp13# Premium conference on Microsoft technologies
Development &
Mobile
• Sometimes you might need to remove or reorder
commits (locally only don’t do that after a push!)
• This can be done interactively with git rebase:
• git rebase –i “HEAD~4”
• Just remove or reorder the lines in the editor:
– pick 37c449c My first commit
– pick 3982180 My second commit
– pick 6055a10 My last commit
Reordering and removing commits
itcampro@ itcamp13# Premium conference on Microsoft technologies
Development &
Mobile
• There’s a good chance that your dev branch
commits will be a mess 
• Git gives you a chance to clean them up before
pushing them upstream using git rebase, e.g.:
• git rebase –i HEAD~3
– pick 37c449c My first commit
– squash 3982180 My second commit
– squash 6055a10 My last commit
Squashing
itcampro@ itcamp13# Premium conference on Microsoft technologies
Development &
Mobile
• Changing the content of the last commit is a
frequent action:
– Typos
– Missing files
– Errors discovered after committing
• Just add --amend to the commit command:
• git commit –a --amend
Change the last commit
itcampro@ itcamp13# Premium conference on Microsoft technologies
Development &
Mobile
• Sometimes you might need to revert a
commit
• Removing a commit is in general a bad idea
unless the commit appear only locally, so
reverting is a good alternative
• git revert <commit>
• This action will generate a new commit
Revert
itcampro@ itcamp13# Premium conference on Microsoft technologies
Development &
Mobile
• There are cases in which the only way to get
out of a messy local repository is to restore it
to a previous state
• git reset --soft <commit>
– Doesn’t modify index and working dir
• git reset --mixed <commit>
– Modifies the index but not the working dir
• git reset --hard <commit>
– Modifies the index AND the working dir
git reset
itcampro@ itcamp13# Premium conference on Microsoft technologies
Development &
Mobile
• .gitignore is a special file in your repository
that contains rules for files and folders that
will not be tracked
• Example:
*.exe
*.dll
*.obj
*.pdb
.gitignore
itcampro@ itcamp13# Premium conference on Microsoft technologies
Development &
Mobile
• On Window you might want to deal with
CRLF / LF on a per-project base
• in .gitattributes add:
• text eol=lf
.gitattributes
itcampro@ itcamp13# Premium conference on Microsoft technologies
Development &
Mobile
• Git provides support for SVN repositories as
well
• There’s quite a lot to discuss on the subject
• Just as an introduction:
• git svn clone <svn_url> <repo.git>
• git svn fetch
• git svn dcommit
Git and Subversion
itcampro@ itcamp13# Premium conference on Microsoft technologies
Development &
Mobile
• Hooks let you run custom code on given
events
• E.g.: for push events:
– pre-receive hook
– for each update ref:
• update hook
• update ref
– post-receive hook
– post-update hook
Hooks
itcampro@ itcamp13# Premium conference on Microsoft technologies
Development &
Mobile
• Hooks are scripts stored in .git/hooks/
• Each script has the name of the hook
– Must be executable (Unix)
• Parameters are passed in the command line
• On Windows, you can use Powershell
– But you need a MSYS script (sh, bash, etc)
#!/bin/bash
powershell -executionpolicy RemoteSigned -
File C:pathpost-receive.ps1 "$@" <
/dev/stdin
Writing hooks
itcampro@ itcamp13# Premium conference on Microsoft technologies
Development &
Mobile
function ProcessRef($old, $new, $ref) {
"old {0} new {1} ref {2}" -f ($old, $new, $ref) |
Out-File -append ”C:Testpost-receive.txt"
}
$lines = while(($line=[Console]::ReadLine())){$line}
foreach($line in $lines)
{
$values = $line.Split(" ")
$old = $values[0]
$new = $values[1]
$ref = $values[2]
ProcessRef $old $new $ref
}
Example Powershell post-receive
itcampro@ itcamp13# Premium conference on Microsoft technologies
Development &
Mobile
• Github did a tremendous job in popularizing Git,
becoming currently the “de facto” standard platform
for open source projects
• Very intuitive and rich web interface
• Fork and pull requests
• Rich APIs for continuous deployment and more
• BitBucket offers similar services, including a limited
number of free private repos
Github, Bitbucket & co.
itcampro@ itcamp13# Premium conference on Microsoft technologies
Development &
MobileFork
itcampro@ itcamp13# Premium conference on Microsoft technologies
Development &
Mobile
• Anybody can fork a public repo
• Users with proper access can fork a private one
• In Github, forks are a good thing
• After committing code to your fork, you can
send a “pull request” to the maintainer of the
original repository
• The maintainer can review it, approve and
merge it
Fork and pull requests
itcampro@ itcamp13# Premium conference on Microsoft technologies
Development &
Mobile
• A modern application lifecycle management
needs to consider a proper framework for:
– Code review
– Unit testing
– Continuous integration
• Integration system tests
– Continuous deployment
• Optionally / Ideally
• Git’s distributed nature helps a lot
Code review, unit testing and CI
itcampro@ itcamp13# Premium conference on Microsoft technologies
Development &
Mobile
• Gerrit is an open source code review solution
based on Git
– https://code.google.com/p/gerrit/
• Written in Java
• Multiplatform
Gerrit
itcampro@ itcamp13# Premium conference on Microsoft technologies
Development &
MobileGerrit
itcampro@ itcamp13# Premium conference on Microsoft technologies
Development &
Mobile
• Git provides a very easy model to extend the
existing command set
• git review is the extension provide for Gerrit
integration
– https://pypi.python.org/pypi/git-review
– Requires Python
• Install on Windows with:
– easy_install.exe git-review
Git review workflow
itcampro@ itcamp13# Premium conference on Microsoft technologies
Development &
Mobile
• git checkout -b newbranch
• git review -s
• git commit -a
• git-review
• Your commits is now available for review on the Gerrit
web site
• Jenkins and CI tools can be executed and vote
• Human review and approval occurs
• Jenkins and CI tools can be executed again
• The commits merge into the master branch
• New versions of the same patchset can be sent with:
• git commit -a --amend
• git review
Gerrit workflow
itcampro@ itcamp13# Premium conference on Microsoft technologies
Development &
MobileGit and Azure web sites
itcampro@ itcamp13# Premium conference on Microsoft technologies
Development &
MobileGit and Azure web sites
itcampro@ itcamp13# Premium conference on Microsoft technologies
Development &
Mobile
• Integrate Powershell with Git?
• http://www.hanselman.com/blog/PromptsAn
dDirectoriesEvenBetterGitAndMercurialWithP
owerShell.aspx
Posh-Git
itcampro@ itcamp13# Premium conference on Microsoft technologies
Q & A

More Related Content

Viewers also liked

Tubettoni e fagioli con le cozze con traduzione dal napoletano all'italiano
Tubettoni e fagioli con le cozze con traduzione dal napoletano all'italianoTubettoni e fagioli con le cozze con traduzione dal napoletano all'italiano
Tubettoni e fagioli con le cozze con traduzione dal napoletano all'italianoTurismoanapoli
 
Il gateau napoletano con traduzione dal napoletano all'italiano
Il gateau  napoletano con traduzione dal napoletano all'italianoIl gateau  napoletano con traduzione dal napoletano all'italiano
Il gateau napoletano con traduzione dal napoletano all'italianoTurismoanapoli
 
Pla de futur de Sant Antoni
Pla de futur de Sant AntoniPla de futur de Sant Antoni
Pla de futur de Sant AntoniEduardCabus
 
Friends epi22 part1
Friends epi22 part1Friends epi22 part1
Friends epi22 part1Peter Sutton
 
06.1 sourcingsmodellen voor extern personeel
06.1 sourcingsmodellen voor extern personeel06.1 sourcingsmodellen voor extern personeel
06.1 sourcingsmodellen voor extern personeelVincent van Rijn
 
How to become a 'specification by example' rocket scientist
How to become a 'specification by example' rocket scientistHow to become a 'specification by example' rocket scientist
How to become a 'specification by example' rocket scientistEquinox IT
 

Viewers also liked (8)

Tubettoni e fagioli con le cozze con traduzione dal napoletano all'italiano
Tubettoni e fagioli con le cozze con traduzione dal napoletano all'italianoTubettoni e fagioli con le cozze con traduzione dal napoletano all'italiano
Tubettoni e fagioli con le cozze con traduzione dal napoletano all'italiano
 
Il gateau napoletano con traduzione dal napoletano all'italiano
Il gateau  napoletano con traduzione dal napoletano all'italianoIl gateau  napoletano con traduzione dal napoletano all'italiano
Il gateau napoletano con traduzione dal napoletano all'italiano
 
Pla de futur de Sant Antoni
Pla de futur de Sant AntoniPla de futur de Sant Antoni
Pla de futur de Sant Antoni
 
Map of africa continent google maps
Map of africa continent   google mapsMap of africa continent   google maps
Map of africa continent google maps
 
Friends epi22 part1
Friends epi22 part1Friends epi22 part1
Friends epi22 part1
 
06.1 sourcingsmodellen voor extern personeel
06.1 sourcingsmodellen voor extern personeel06.1 sourcingsmodellen voor extern personeel
06.1 sourcingsmodellen voor extern personeel
 
How to become a 'specification by example' rocket scientist
How to become a 'specification by example' rocket scientistHow to become a 'specification by example' rocket scientist
How to become a 'specification by example' rocket scientist
 
Git tips
Git tipsGit tips
Git tips
 

More from Alessandro Pilotti

OpenStack and Windows - What's new in Ocata
OpenStack and Windows - What's new in OcataOpenStack and Windows - What's new in Ocata
OpenStack and Windows - What's new in OcataAlessandro Pilotti
 
Strategies for migrating workloads from VMware to OpenStack
Strategies for migrating workloads from VMware to OpenStackStrategies for migrating workloads from VMware to OpenStack
Strategies for migrating workloads from VMware to OpenStackAlessandro Pilotti
 
OpenStack + Nano Server + Hyper-V + S2D
OpenStack + Nano Server + Hyper-V + S2DOpenStack + Nano Server + Hyper-V + S2D
OpenStack + Nano Server + Hyper-V + S2DAlessandro Pilotti
 
Building a Microsoft cloud with open technologies
Building a Microsoft cloud with open technologiesBuilding a Microsoft cloud with open technologies
Building a Microsoft cloud with open technologiesAlessandro Pilotti
 
OpenStack Summit 2013 Hong Kong - OpenStack and Windows
OpenStack Summit 2013 Hong Kong - OpenStack and WindowsOpenStack Summit 2013 Hong Kong - OpenStack and Windows
OpenStack Summit 2013 Hong Kong - OpenStack and WindowsAlessandro Pilotti
 
Interoperable OpenStack guest provisioning with Cloudbase-Init
Interoperable OpenStack guest provisioning with Cloudbase-InitInteroperable OpenStack guest provisioning with Cloudbase-Init
Interoperable OpenStack guest provisioning with Cloudbase-InitAlessandro Pilotti
 
An HTML5 client to connect to the Hyper-V console
An HTML5 client to connect to the Hyper-V consoleAn HTML5 client to connect to the Hyper-V console
An HTML5 client to connect to the Hyper-V consoleAlessandro Pilotti
 
Hyper-V OpenStack Nova Compute
Hyper-V OpenStack Nova ComputeHyper-V OpenStack Nova Compute
Hyper-V OpenStack Nova ComputeAlessandro Pilotti
 
Drupal, Memcache and Solr on Windows
Drupal, Memcache and Solr on WindowsDrupal, Memcache and Solr on Windows
Drupal, Memcache and Solr on WindowsAlessandro Pilotti
 
PHP and FastCGI Performance Optimizations
PHP and FastCGI Performance OptimizationsPHP and FastCGI Performance Optimizations
PHP and FastCGI Performance OptimizationsAlessandro Pilotti
 
Managing Drupal on Windows with Drush
Managing Drupal on Windows with DrushManaging Drupal on Windows with Drush
Managing Drupal on Windows with DrushAlessandro Pilotti
 
Building drupal web farms with IIS - part 1
Building drupal web farms with IIS - part 1Building drupal web farms with IIS - part 1
Building drupal web farms with IIS - part 1Alessandro Pilotti
 
Building modern web sites with ASP .Net Web API, WebSockets and RSignal
Building modern web sites with ASP .Net Web API, WebSockets and RSignalBuilding modern web sites with ASP .Net Web API, WebSockets and RSignal
Building modern web sites with ASP .Net Web API, WebSockets and RSignalAlessandro Pilotti
 

More from Alessandro Pilotti (16)

OpenStack and Windows - What's new in Ocata
OpenStack and Windows - What's new in OcataOpenStack and Windows - What's new in Ocata
OpenStack and Windows - What's new in Ocata
 
Strategies for migrating workloads from VMware to OpenStack
Strategies for migrating workloads from VMware to OpenStackStrategies for migrating workloads from VMware to OpenStack
Strategies for migrating workloads from VMware to OpenStack
 
Puppet + Windows Nano Server
Puppet + Windows Nano ServerPuppet + Windows Nano Server
Puppet + Windows Nano Server
 
OpenStack + Nano Server + Hyper-V + S2D
OpenStack + Nano Server + Hyper-V + S2DOpenStack + Nano Server + Hyper-V + S2D
OpenStack + Nano Server + Hyper-V + S2D
 
Building a Microsoft cloud with open technologies
Building a Microsoft cloud with open technologiesBuilding a Microsoft cloud with open technologies
Building a Microsoft cloud with open technologies
 
OpenStack Summit 2013 Hong Kong - OpenStack and Windows
OpenStack Summit 2013 Hong Kong - OpenStack and WindowsOpenStack Summit 2013 Hong Kong - OpenStack and Windows
OpenStack Summit 2013 Hong Kong - OpenStack and Windows
 
Interoperable OpenStack guest provisioning with Cloudbase-Init
Interoperable OpenStack guest provisioning with Cloudbase-InitInteroperable OpenStack guest provisioning with Cloudbase-Init
Interoperable OpenStack guest provisioning with Cloudbase-Init
 
OpenStack and Windows
OpenStack and WindowsOpenStack and Windows
OpenStack and Windows
 
An HTML5 client to connect to the Hyper-V console
An HTML5 client to connect to the Hyper-V consoleAn HTML5 client to connect to the Hyper-V console
An HTML5 client to connect to the Hyper-V console
 
Hyper-V OpenStack Nova Compute
Hyper-V OpenStack Nova ComputeHyper-V OpenStack Nova Compute
Hyper-V OpenStack Nova Compute
 
Drupal, Memcache and Solr on Windows
Drupal, Memcache and Solr on WindowsDrupal, Memcache and Solr on Windows
Drupal, Memcache and Solr on Windows
 
PHP and FastCGI Performance Optimizations
PHP and FastCGI Performance OptimizationsPHP and FastCGI Performance Optimizations
PHP and FastCGI Performance Optimizations
 
Managing Drupal on Windows with Drush
Managing Drupal on Windows with DrushManaging Drupal on Windows with Drush
Managing Drupal on Windows with Drush
 
Building drupal web farms with IIS - part 1
Building drupal web farms with IIS - part 1Building drupal web farms with IIS - part 1
Building drupal web farms with IIS - part 1
 
Windows Loves drupal
Windows Loves drupalWindows Loves drupal
Windows Loves drupal
 
Building modern web sites with ASP .Net Web API, WebSockets and RSignal
Building modern web sites with ASP .Net Web API, WebSockets and RSignalBuilding modern web sites with ASP .Net Web API, WebSockets and RSignal
Building modern web sites with ASP .Net Web API, WebSockets and RSignal
 

Recently uploaded

Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...apidays
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusZilliz
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 

Recently uploaded (20)

Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 

Git crash course for Visual Studio devs

  • 1. itcampro@ itcamp13# Premium conference on Microsoft technologies Git crash course for Visual Studio devs Alessandro Pilotti Cloudbase Solutions MVP ASP.Net / IIS @alexpilotti
  • 2. itcampro@ itcamp13# Premium conference on Microsoft technologies Development & MobileHuge thanks to our sponsors!
  • 3. itcampro@ itcamp13# Premium conference on Microsoft technologies Development & Mobile • Why Git? • Basics • Visual Studio integration • Remote repositories • Branching • Merging and rebasing • Forks and github, bitbucket, etc • Continuous deployment • Gerrit • Azure support Agenda
  • 4. itcampro@ itcamp13# Premium conference on Microsoft technologies Development & Mobile • Why do we need an ENTIRE session on a VCS instead of talking about code?  • Previous VCS are so simple: – CVS – Subversion – Sourcesafe (D’oh) • In short, it’s because there’s way more than the usual commit / checkout thing  Why Git?
  • 5. itcampro@ itcamp13# Premium conference on Microsoft technologies Development & Mobile • Developed initially by Linus Torvalds in 2005 – Used for the Linux Kernel – GPLv2 – Multiplatform (Linux, Windows, OSX, FreeBSD) • Some design goals: – Fast and efficient – Support for non linear development – Distributed – Easy publishing – Garbage collection Git
  • 6. itcampro@ itcamp13# Premium conference on Microsoft technologies Development & Mobile • In most cases, you just start work on a project using it  – In my case, OpenStack • Most OSS projects are hosted on github – CodePlex supports Git as well • Ease to branch, merge, fork • Once you start using it, it’s hard to go back Why should I use it?
  • 7. itcampro@ itcamp13# Premium conference on Microsoft technologies Development & Mobile • http://msysgit.github.io/ – Command line • http://windows.github.com/ • Visual Studio 2012 Update 2 • NetBeans • Eclipse • TortoiseGit • etc Windows clients
  • 8. itcampro@ itcamp13# Premium conference on Microsoft technologies Development & Mobile • A Git repository is a directory tree containing your project(s) – A hidden directory “.git” contains all the Git stuff • Start a repo from scratch: – git init • Cloned from an existing repo: – git clone https://github.com/cloudbase/cloudbase-init Basics
  • 9. itcampro@ itcamp13# Premium conference on Microsoft technologies Development & Mobile • Files are either: – Staged (git knows about them) – Untracked (git doesn’t care about them) • To stage a file / directory: – git add path • To unstage and delete a file: – git rm path • To unstage w/o deleting it: – git rm –cached path Staging files
  • 10. itcampro@ itcamp13# Premium conference on Microsoft technologies Development & Mobile • As simple as: – git commit –a –m “Don’t forget the commit msg” • To commit a file: – git commit -m msg path • Being a distributed VCS, a commit is only local • Do small commits, atomic and cohesive – With a clear commit message – A VCS is not a backup tool  Commit
  • 11. itcampro@ itcamp13# Premium conference on Microsoft technologies Development & Mobile • You can look at the history for the current branch with a simple: – git log – git log --pretty=oneline • To see your staged (uncommitted) changes: – diff format – git diff • To see the differences between two commits: – git diff commit1 commit2 Git log, show and diff
  • 12. itcampro@ itcamp13# Premium conference on Microsoft technologies Development & Mobile • With checkout you can get a file or a working copy of your repository: – E.g.: to undo your work to the latest commit: – git checkout (entire repo) – git checkout file (single file only) • To checkout a file to a previous version: – git checkout commitref file – E.g.: to get the previous version: • git checkout HEAD^ file • git checkout HEAD^ checkout
  • 13. itcampro@ itcamp13# Premium conference on Microsoft technologies Development & Mobile • git config --global user.name ”My Name” • git config --global user.email myuser@mydomain.com • git config --global color.ui true • git config --global core.editor notepad++ – Note: add the editor to your path first (elevated console): • SETX PATH “%PATH%;%ProgramFiles% (x86)Notepad++” /M – Even better, getting used to vi is not so terrible  • git config --global core.autocrlf true – Values: true, input, false – Set true if you work on multiplatform projects – See .gitattributes later for this as well Global settings
  • 14. itcampro@ itcamp13# Premium conference on Microsoft technologies Development & MobileGit and Visual Studio 2012
  • 15. itcampro@ itcamp13# Premium conference on Microsoft technologies Development & Mobile • VS 2012 Update 2 required • Install Visual Studio Tools for Git • Tools -> Options -> Source Control – Choose “Microsoft Git provider” • Open “Team Explorer” – View -> Team Explorer • You can use also regular git commands in – Package Manager Console Git and Visual Studio 2012
  • 16. itcampro@ itcamp13# Premium conference on Microsoft technologies Development & Mobile • Connect to Team Projects (socket icon) – Clone – Set the remote repo URL – Specify a local path VS 2012 Clone a repo
  • 17. itcampro@ itcamp13# Premium conference on Microsoft technologies Development & Mobile • RC available now • http://blogs.msdn.com/b/visualstudioalm/arc hive/2013/05/07/release-candidate-to-visual- studio-update-3-now-available.aspx • Bug fixes • Git TFS continuous integration support VS 2012 Update 3
  • 18. itcampro@ itcamp13# Premium conference on Microsoft technologies Development & MobileVS2012 U3 Git
  • 19. itcampro@ itcamp13# Premium conference on Microsoft technologies Development & MobileTFS + Git TFS supports GIT natively! http://bit.ly/Z1RkcV Signup for a free account here: https://tfs.app.visualstudio.com/_account/Signu p
  • 20. itcampro@ itcamp13# Premium conference on Microsoft technologies VS2012 GIT DEMO
  • 21. itcampro@ itcamp13# Premium conference on Microsoft technologies Development & Mobile • git contains all the info related to your repo in “.git/” • Your files (working copy), are simply a human readable copy of the files  – Bare repositories have no working copy • The Index contains info about staged files • File contents are stored into blobs • Other objects include trees (the filesystem refresentation) and commits • Every object is identified with a SHA1 hash A bit of internals
  • 22. itcampro@ itcamp13# Premium conference on Microsoft technologies Development & Mobile • You can refer to commits with their SHA1 hash or with a shorter unique prefix, e.g.: – git log e46bf2165f29f579051b8e12ebe63e5512205610 – git log e46bf2 • Or you can refer to a commit using a reference: – every branch has a “head” identifying the last commit • git checkout branchname Refs
  • 23. itcampro@ itcamp13# Premium conference on Microsoft technologies Development & Mobile • HEAD is a special symbolic link pointing to the head of the current branch • You can do some “arithmetic” with refs: – ^ points to the previous commit – ~n points to the nth previous commit – HEAD^^^ the 3rd commit before HEAD – HEAD~3 (same as the above example) • Note: use (quotes) “HEAD^” in the Windows cmd prompt Refs
  • 24. itcampro@ itcamp13# Premium conference on Microsoft technologies Development & Mobile • A tag is simply a friendly name for a commit – git tag v1.0 HEAD • Annotated tags are stored as full objects: – git tag –a v1.0 –m “Version 1.0” HEAD • Don’t confuse tags with a branches Tags
  • 25. itcampro@ itcamp13# Premium conference on Microsoft technologies Development & Mobile • Git is a distributed VCS • You can “sync” your local copy with remote copies anytime, by either “pull” or “push” changes • Git has no concept of a “server” – Repos form a peer network • It’s useful anyway to elect an “authoritative” repository. E.g.: – A repo on github, bitbucket, etc – The project lead developer’s repo Remote repositories
  • 26. itcampro@ itcamp13# Premium conference on Microsoft technologies Development & Mobile • A remote is simple a name and an url • List remotes: – git remote • Add a remote: – git add origin https://github.com/openstack/nova.git • Note: this will track all remote branches, use –t <branchname> to limit • Protocols to access the remote repo can be: – Local filesystem, HTTP/HTTPS, git, rsync – Local fileystem on Windows: • file:///c/your/path/repo.git Configuring remotes
  • 27. itcampro@ itcamp13# Premium conference on Microsoft technologies Development & Mobile • Remove a remote: – git remote rm name • Changing a remote url is a frequent operation: – git remote set-url <newurl> <remote_name> • Cleaning stale remote tracking branches – git remote prune <remote_name> Configuring remotes
  • 28. itcampro@ itcamp13# Premium conference on Microsoft technologies Development & Mobile • A bare repository doesn’t have a working copy of your content • Use it when you create an authoritative “server” repo • By convention bare repo folder names end it “.git” e.g.: “myrepo.git” • git init --bare Bare repositories
  • 29. itcampro@ itcamp13# Premium conference on Microsoft technologies Development & Mobile • A typical operation consists in cloning a remote repository (will set the proper remote as well): – git clone <url> • To update a local repository with remote commits: – git pull • This is a shortcut for git fetch and git merge FETCH_HEAD Clone / pull
  • 30. itcampro@ itcamp13# Premium conference on Microsoft technologies Development & Mobile • Updating a remote repository consists in: – git push <remote> <branch> – git push origin master • Note: you must first make sure that you pulled all the remote commits first! • More on merging / rebasing later! Push
  • 31. itcampro@ itcamp13# Premium conference on Microsoft technologies Development & Mobile • Git was created to make branching and merging as easy as possible. • “master” is the default branch • From an application lifecycle standpoint we can define two types of branches: – Long lived • Typically major releases – Short lived • Bug fixes, dev experiments, etc • Git makes no difference of course Branches
  • 32. itcampro@ itcamp13# Premium conference on Microsoft technologies Development & Mobile • Creating a branch is simply: – git chekout –b name – Shortcut for git branch name and git checkout name • Switch to a different branch: – git checkout name – This will also change the working directory contents to reflect the branch commits!! • To list existing branches: – git branch – The active branch is marked with “*” • To remove a branch: – git branch –d name Branches
  • 33. itcampro@ itcamp13# Premium conference on Microsoft technologies Development & MobileHow does it look like? A B C Dmaster new-feature E F experiment master commits: A, B, D new-feature commits: A, B, C, E experiment commits : A, B, C, E, F
  • 34. itcampro@ itcamp13# Premium conference on Microsoft technologies Development & Mobile • In most cases at some point you’d like to merge the content of a branch into another • For example, you develop a new feature and once it’s done tested and reviewed you want to merge it in the master branch • git-merge merges a branch into the current one: – git checkout master – git merge new-feature Merge
  • 35. itcampro@ itcamp13# Premium conference on Microsoft technologies Development & MobileHere’s how a merge looks like A B C Dmaster new-feature E F experiment G master commits: A, B, D, C, E, G
  • 36. itcampro@ itcamp13# Premium conference on Microsoft technologies Development & Mobile • What happens when the same file has been changed in two branches? • Git is very smart in applying different commit patches to the same source when lines do not overlap (e.g. 2 different methods) • But sometimes you just have to handle conflicts, it’s a hard life  Conflicts
  • 37. itcampro@ itcamp13# Premium conference on Microsoft technologies Development & Mobile git merge branch_name CONFLICT (content): Merge conflict in test.txt Automatic merge failed; fix conflicts and then commit the result. D’oh! Edit the conflicting files… git add files git commit -a Conflicts
  • 38. itcampro@ itcamp13# Premium conference on Microsoft technologies Development & Mobile • You can also rollback the merge with: – git merge –abort • A merge happens also when you pull a remote branch – The resolution process is the same • Once the merge succeeds, you can delete the merged branch if you don’t need it anymore • You can also keep on working on the merged branch and merge it again later • When you merge a branch w/o conflicts (fast-forwarding) by default a merge commit is not created. This can be changed with git merge –no-ff etc Merge notes
  • 39. itcampro@ itcamp13# Premium conference on Microsoft technologies Development & Mobile • Rebasing a branch consists in taking the commits of another branch and applying them on the current branch before any commit added to the current branch. • Typically this is used to bring a local branch up to date with remote commits • Merge vs rebase can create a bit of confusion to users Rebase
  • 40. itcampro@ itcamp13# Premium conference on Microsoft technologies Development & MobileRebase example A B C Dmaster new-feature E F git checkout new-feature git rebase master Note: rebased commits have a new hash!
  • 41. itcampro@ itcamp13# Premium conference on Microsoft technologies Development & Mobile CONFLICT (content): Merge conflict in test3.txt Failed to merge in the changes. Patch failed at 0002 asdasdd The copy of the patch that failed is found in: /Users/anorex/Downloads/testgit/.git/rebase-apply/patch When you have resolved this problem, run "git rebase --continue". If you prefer to skip this patch, run "git rebase --skip" instead. To check out the original branch and stop rebasing, run "git rebase - -abort". Rebase conflicts • Similar to resolving a merge
  • 42. itcampro@ itcamp13# Premium conference on Microsoft technologies Development & Mobile • What if you just one to pick a single commit from another branch without having to merge / rebase the entire branch? • E.g. backporting a bug fix from v1.2 to v1.1 • git cherry-pick commit1 • git cherry-pick start..end Cherry picking
  • 43. itcampro@ itcamp13# Premium conference on Microsoft technologies Development & MobileCherry-pick example A B C Dmaster new-feature E F D ’ git checkout new-feature git cherry-pick D Note: cherry-picked commits have a new hash!
  • 44. itcampro@ itcamp13# Premium conference on Microsoft technologies Development & Mobile • Sometimes you might need to remove or reorder commits (locally only don’t do that after a push!) • This can be done interactively with git rebase: • git rebase –i “HEAD~4” • Just remove or reorder the lines in the editor: – pick 37c449c My first commit – pick 3982180 My second commit – pick 6055a10 My last commit Reordering and removing commits
  • 45. itcampro@ itcamp13# Premium conference on Microsoft technologies Development & Mobile • There’s a good chance that your dev branch commits will be a mess  • Git gives you a chance to clean them up before pushing them upstream using git rebase, e.g.: • git rebase –i HEAD~3 – pick 37c449c My first commit – squash 3982180 My second commit – squash 6055a10 My last commit Squashing
  • 46. itcampro@ itcamp13# Premium conference on Microsoft technologies Development & Mobile • Changing the content of the last commit is a frequent action: – Typos – Missing files – Errors discovered after committing • Just add --amend to the commit command: • git commit –a --amend Change the last commit
  • 47. itcampro@ itcamp13# Premium conference on Microsoft technologies Development & Mobile • Sometimes you might need to revert a commit • Removing a commit is in general a bad idea unless the commit appear only locally, so reverting is a good alternative • git revert <commit> • This action will generate a new commit Revert
  • 48. itcampro@ itcamp13# Premium conference on Microsoft technologies Development & Mobile • There are cases in which the only way to get out of a messy local repository is to restore it to a previous state • git reset --soft <commit> – Doesn’t modify index and working dir • git reset --mixed <commit> – Modifies the index but not the working dir • git reset --hard <commit> – Modifies the index AND the working dir git reset
  • 49. itcampro@ itcamp13# Premium conference on Microsoft technologies Development & Mobile • .gitignore is a special file in your repository that contains rules for files and folders that will not be tracked • Example: *.exe *.dll *.obj *.pdb .gitignore
  • 50. itcampro@ itcamp13# Premium conference on Microsoft technologies Development & Mobile • On Window you might want to deal with CRLF / LF on a per-project base • in .gitattributes add: • text eol=lf .gitattributes
  • 51. itcampro@ itcamp13# Premium conference on Microsoft technologies Development & Mobile • Git provides support for SVN repositories as well • There’s quite a lot to discuss on the subject • Just as an introduction: • git svn clone <svn_url> <repo.git> • git svn fetch • git svn dcommit Git and Subversion
  • 52. itcampro@ itcamp13# Premium conference on Microsoft technologies Development & Mobile • Hooks let you run custom code on given events • E.g.: for push events: – pre-receive hook – for each update ref: • update hook • update ref – post-receive hook – post-update hook Hooks
  • 53. itcampro@ itcamp13# Premium conference on Microsoft technologies Development & Mobile • Hooks are scripts stored in .git/hooks/ • Each script has the name of the hook – Must be executable (Unix) • Parameters are passed in the command line • On Windows, you can use Powershell – But you need a MSYS script (sh, bash, etc) #!/bin/bash powershell -executionpolicy RemoteSigned - File C:pathpost-receive.ps1 "$@" < /dev/stdin Writing hooks
  • 54. itcampro@ itcamp13# Premium conference on Microsoft technologies Development & Mobile function ProcessRef($old, $new, $ref) { "old {0} new {1} ref {2}" -f ($old, $new, $ref) | Out-File -append ”C:Testpost-receive.txt" } $lines = while(($line=[Console]::ReadLine())){$line} foreach($line in $lines) { $values = $line.Split(" ") $old = $values[0] $new = $values[1] $ref = $values[2] ProcessRef $old $new $ref } Example Powershell post-receive
  • 55. itcampro@ itcamp13# Premium conference on Microsoft technologies Development & Mobile • Github did a tremendous job in popularizing Git, becoming currently the “de facto” standard platform for open source projects • Very intuitive and rich web interface • Fork and pull requests • Rich APIs for continuous deployment and more • BitBucket offers similar services, including a limited number of free private repos Github, Bitbucket & co.
  • 56. itcampro@ itcamp13# Premium conference on Microsoft technologies Development & MobileFork
  • 57. itcampro@ itcamp13# Premium conference on Microsoft technologies Development & Mobile • Anybody can fork a public repo • Users with proper access can fork a private one • In Github, forks are a good thing • After committing code to your fork, you can send a “pull request” to the maintainer of the original repository • The maintainer can review it, approve and merge it Fork and pull requests
  • 58. itcampro@ itcamp13# Premium conference on Microsoft technologies Development & Mobile • A modern application lifecycle management needs to consider a proper framework for: – Code review – Unit testing – Continuous integration • Integration system tests – Continuous deployment • Optionally / Ideally • Git’s distributed nature helps a lot Code review, unit testing and CI
  • 59. itcampro@ itcamp13# Premium conference on Microsoft technologies Development & Mobile • Gerrit is an open source code review solution based on Git – https://code.google.com/p/gerrit/ • Written in Java • Multiplatform Gerrit
  • 60. itcampro@ itcamp13# Premium conference on Microsoft technologies Development & MobileGerrit
  • 61. itcampro@ itcamp13# Premium conference on Microsoft technologies Development & Mobile • Git provides a very easy model to extend the existing command set • git review is the extension provide for Gerrit integration – https://pypi.python.org/pypi/git-review – Requires Python • Install on Windows with: – easy_install.exe git-review Git review workflow
  • 62. itcampro@ itcamp13# Premium conference on Microsoft technologies Development & Mobile • git checkout -b newbranch • git review -s • git commit -a • git-review • Your commits is now available for review on the Gerrit web site • Jenkins and CI tools can be executed and vote • Human review and approval occurs • Jenkins and CI tools can be executed again • The commits merge into the master branch • New versions of the same patchset can be sent with: • git commit -a --amend • git review Gerrit workflow
  • 63. itcampro@ itcamp13# Premium conference on Microsoft technologies Development & MobileGit and Azure web sites
  • 64. itcampro@ itcamp13# Premium conference on Microsoft technologies Development & MobileGit and Azure web sites
  • 65. itcampro@ itcamp13# Premium conference on Microsoft technologies Development & Mobile • Integrate Powershell with Git? • http://www.hanselman.com/blog/PromptsAn dDirectoriesEvenBetterGitAndMercurialWithP owerShell.aspx Posh-Git
  • 66. itcampro@ itcamp13# Premium conference on Microsoft technologies Q & A