2. .
wwhhooaammii
JJuulliieenn PPiivvoottttoo
• System administrator at inuits.eu
• Git user for 5+ years
• DevOps believer
• Open-source defender since 2004
• roidelapluie on twitter/github
3. .
OOppss <<33 DDeevv
• Infrastructure as Code
▶ SCM all the things
▶ Monitoring
▶ Configuration
▶ Application deployment
• Taking part of software development
▶ Understanding
▶ Monitoring
▶ High Availability
▶ …
4. .
MMee aanndd ggiitt
• I first used subversion (10 years ago)
• Private forges and sourceforge
• 5 years later a lot of projects moved to git
• The Puppet community also uses a lot git
• Git/Hg are the de-facto standards in OS
projects
5. .
Git is a free and open source distributed version control system
designed to handle everything from small to very large projects
with speed and efficiency.
Source: http://git-scm.com/
6. .
ggiitt lloogg
• Initiated in 2005 by Linus Torvalds
• Replacement of closed-source BitKeeper
• Created for the Linux Kernel development
• Now used by thousands of projects
7. .
ggiitt iiss ddiissttrriibbuutteedd
• Everything can be done in local (exept
pull&push)
• Work with several remotes
• Share code with anyone
• No unique central repository
• A lot of workflows possible
10. .
ggiitt iiss ooppeenn--ssoouurrccee
• Published under GPL-2
• Written in C
• A lot of frontends/backends
• A lot of libraries
• A lot of hosting services
• And a lot of users
11. .
MMuullttiippllee ggiitt rreeppooss:: wwhhyy??
• Code isolation: plugins, libraries
• Getting faster feedback from testing
• Contributing back to upstream projects
• Separate apps that are released together
• Share code between projects
12. .
MMuullttiippllee ggiitt rreeppooss uusseeccaasseess
• Infrastructure as Code
• Projects released together
• Projects that embed external libraries
• …
14. .
ggiitt ssuubbmmoodduulleess
• Built-in with git
• Embeds external repositories in a
subdirectory or your repo
• Points these external repositories in a
particular commit
15. .
ggiitt ssuubbmmoodduulleess
• Submodules act like traditional git
repositories
• Super repo contains a file with the
submodules urls
• Super repo contains objects that can be
updated with commit hashes
18. .
AAdddd ffiirrssttmmoodduullee iinn ppaarreenntt rreeppoo
.
$ git submodule add ../subrepo/ subrepo
Cloning into 'subrepo'...
done.
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
.
new file: .gitmodules
new file: subrepo
19. .
WWhhaatt jjuusstt hhaappppeenneedd??
• git created a .gitmodules file
• It cloned the subrepo in a directory
• It created a git object that points to the repo
• That object contains the git revision
20. .
..ggiittmmoodduulleess ffiillee
.
$ cat .gitmodules
[submodule "subrepo"]
.
path = subrepo
url = ../subrepo/
• Unique file for all the submodules
• Only contains the path and the url
• In this case, we use relative URL
25. .
WWoorrkkiinngg iinn aa ssuubbmmoodduullee
.
$ cd subrepo
$ > newfile
$ git add newfile
$ git commit -m "add newfile"
[detached HEAD 6ee0e71] add newfile
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 newfile
$ git push
fatal: You are not currently on a branch.
To push the history leading to the current (detached HEAD)
state now, use
.
git push origin HEAD:<name-of-remote-branch>
26. .
CChheecckkiinngg oouutt aa bbrraanncchh
.
$ git checkout master
Warning: you are leaving 1 commit behind, not connected
to any of your branches:
6ee0e71 add newfile
If you want to keep them by creating a new branch, this
may be a good time to do so with:
git branch new_branch_name 6ee0e71
Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.
.
30. .
LLeett''ss rreewwiinndd....
• A submodule not attached to a branch
▶ Because submodules are referenced by their commit hash
only
▶ It is called the DETACHED HEAD
• How to push then?
▶ The easy/safe option is to checkout a branch
• You only need to do that once
31. .
ggiitt ssuubbmmoodduullee ffoorreeaacchh
• git submodule foreach allow you to run a
command on each repo
▶ git submodule foreach git checkout master
▶ git submodule foreach ls
▶ git submodule foreach git commit -am "foo"
32. .
MMeeaannwwhhiillee,, oonn tthhee ssuuppeerr--pprroojjeecctt……
.
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be
committed)
(use "git checkout -- <file>..." to discard changes in
working directory)
.
modified: subrepo (new commits)
no changes added to commit (use "git add" and/or "git
commit -a")
34. .
LLooggss
.
$ git log -p --submodule=log subrepo/
commit 731626bc53d8c248647443b4c0523d96d316cd24
Author: Julien Pivotto <roidelapluie@inuits.eu>
Date: Sat Oct 25 22:26:56 2014 +0200
.
update subrepo
Submodule subrepo 41e64b6..01c1b9c:
> work on newfile
> update newfile
> add newfile
35. .
CChhaannggee aa ssuubbmmoodduulleess UURRLL
• Edit .gitmodules and commit the file
• Run git submodule sync
• Now the submodule will use the new URL
36. .
ggiitt ssuubbmmoodduullee ----rreeccuurrssiivvee
• Run commands recursively
• You can get multiple levels of submodules
• But you add complexity
▶ Each level is 1 more commit you need to write
▶ Playing with remote urls becomes tricky of you work with
remotes
37. .
SSuubbmmoodduulleess iinntteeggrraattiioonn
• Integrated in git, standard
• Integrated in CI tools (Jenkins)
• Nothing specific needed for pulling
• Need to checkout the submodules after
pulling
38. .
SSuubbmmoodduulleess iinn GGeerrrriitt
• Gerrit integrates submodules
• It can create commits in "super-repo" if a
code change is merged
• Not a perfect way of doing if changes in two
repo's are depending of each other
39. .
SSuubbmmoodduulleess iinn GGeerrrriitt
• Gerrit is integrated in CI tools
• Gerrit allows fine tuning ACL
• Gerrit code reviews with submodules
changes don't display changes in the
submodules
40. .
SSuubbmmoodduulleess pprrooss aanndd ccoonnss
Each commit in submodule is not in
super-repo
It is easy to rollback by accident a
submodule
Getting logs is not easy
You can forget to update super-repo
Submodules are not attached to a branch
41. .
SSuubbmmoodduulleess pprrooss aanndd ccoonnss
+ Built-in
+ Can use relative urls
+ You can control the version of the
submodules
+ Supported by many tools
+ Easy rollbacks of submodules
+ git bissect works (on the super repo)
46. .
CClloonniinngg aa rreeppoo
.
$ gits clone ../superrepo/ .
Cloning into '.'...
done.
Cloning into 'subrepo'...
done.
.
47. .
WWoorrkkiinngg iinn ssuubbmmoodduulleess
.
$ cd subrepo
$ date newfile
$ git add newfile
$ gits commit -m Work on newfile
On: subrepo:
[master 1230de3] Work on newfile
.
1 file changed, 1 insertion(+), 1 deletion(-)
On: (super-repo):
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean
48. .
PPuusshhiinngg cchhaannggeess
.
$ gits push
On: subrepo:
To /home/roidelapluie/subrepo/
.
fbcf73c..1230de3 master - master
On: (super-repo):
Everything up-to-date
50. .
ggiitt ssllaavvee wwoorrkkffllooww
• Subrepos are always attached to a branch
• You can work within them normally
• Run almost any git command with gits
51. .
PPeerrffoorrmmaannccee
• gits --parallel 8: run 8 parallel git commands
• No extra commit in the super repository
• Close to traditional git workflow
52. .
AA bbrraanncchhiinngg aapppprrooaacchh
• Use gits branch and gits checkout to switch
between branches
• All the repositories will switch branches (e.g
1.0, 1.1)
• Easy merge with gits merge
• Avoid upstream traditional branch names
53. .
ggiittss oouuttppuutt
• gits will simplify the output of git
commands
• It will group the repos by output
• Easier to see the status, the remotes, etc
54. .
PPrrooss aanndd ccoonnss ooff ggiittssllaavvee
Not integrated in tools
Requires an additional binary
Not integrated in git
Hard to rollback on every repositories
55. .
PPrrooss aanndd ccoonnss ooff ggiittssllaavvee
+ Close to git workflow
+ Less error-prone
+ Use traditional git commands
+ Every git push arrives in the repo
56. .
MMiittiiggeeaattee ggiittssllaavveess'' iissssuueess
• Use git hooks to trigger tests on CI
▶ Polling SCM does not scale anyway
▶ Use the Quite period feature
• Use CI to add the same tag in each
repository
▶ Rollback to a tag, not a commit
▶ Add a tag at each commit
58. .
UUssee SSSSHH ssoocckkeettss
.
$ cat .ssh/config
Host githost
.
controlmaster auto
controlpath /tmp/ssh-%r@%h:%p
ControlPersist 300
• Use only one SSH connection
• Do not disconnect SSH
60. .
ggiitt aauuttooccoorrrreecctt
.
$ git config help.autocorrect 10
$ git pusk
WARNING: You called a Git command named 'pusk', which does not Continuing under the assumption that you meant 'push'
in 1.0 seconds automatically...
.
61. .
UUssee ggiitt hhooookkss
• Multiple repositories = a lot of pull
• Jenkins pulling X repos X times every 5
minutes is a bad idea
• Git hooks to the resue
• Reduce load on Jenkins and the git server
• Reduce the time before Jenkins launches
builds
62. .
GGPPGG--SSiiggnn yyoouurr ccoommmmiittss
• git commit -S
• Sign PR, merge commits
• Do not sign every commit (then it becomes
useless)
65. .
CCoonncclluussiioonnss
• Git is an awesome, extandable tool
• There are several ways to manage multiple
git repositories
• Working with multiple repos is easy
• You have to learn tools anyway
• Experiment them and pick one :-)