Wrapped in a single session, you'll find the concepts and techniques that convert the average Git practitioner into a master of the craft. We'll go from technical topics like "efficient conflict resolution" and "effective code cleanup," to the often-asked "how to handle project dependencies with Git" and "how to manage massive repositories." And much more.
2. Becoming a Git Master:
Concepts and Techniques to convert you
into a master of the DVCS craft
NICOLA PAOLUCCI • DEVELOPER ADVOCATE • ATLASSIAN • @DURDN
3. Becoming a Git Master:
Concepts and Techniques to convert you
into a master of the DVCS craft
NICOLA PAOLUCCI • DEVELOPER ADVOCATE • ATLASSIAN • @DURDN
4. Marcus Bertrand
Tim Pettersen
I'm George. George McFly.
I'm your density… I mean,
your destiny
Stefan Saasen
Sarah Goff Dupont
13. PRO ALIASES & PROMPT
Basic Alias Form
Very simple:
ls = log --oneline
[vagrant@vagrant-ubuntu-trusty-64:/home/vagrant/buildstep] master ± git ls
90aa814 Merge pull request #85 from marqu3z/master
f1eb16b overwrite source.list
e6b9d16 change repo before prepare task
8bc10c0 Fix for deprecated repository
e34d861 Link to buildpacks.txt instead
4502635 Merge pull request #76 from elia/fix-72-no-buildpack-bundle-install
38be796 Bundle install ain't needed against the buildpack
14. PRO ALIASES & PROMPT
You can do great things with just this
For example: amend the last commit with
everything I have here uncommitted and new
caa = commit -a --amend -C HEAD
18. PRO ALIASES & PROMPT
For multiple commands or complex
parameters use a bash function!
You can escape to a shell with ! like this:
my_alias = "!f() { <command> }; f”
19. PRO ALIASES & PROMPT
Some useful shortcuts and variables
More in any bash manual
$1 - first command line parameter
$2 - second command line parameter
$@ - all command line parameters passed
21. PRO ALIASES & PROMPT
What can you do with this?
Cool cool things, for example add a Bitbucket remote:
git remote add $1 https://bitbucket.org/$2.git;
22. PRO ALIASES & PROMPT
ra = "!f() {
}; f"
What can you do with this?
Cool cool things, for example add a Bitbucket remote:
git remote add $1 https://bitbucket.org/$2.git;
23. PRO ALIASES & PROMPT
ra = "!f() {
}; f"
What can you do with this?
Cool cool things, for example add a Bitbucket remote:
git remote add $1 https://bitbucket.org/$2.git;
git ra jsmith jsmith/prj
24. PRO ALIASES & PROMPT
ra = "!f() {
}; f"
What can you do with this?
Cool cool things, for example add a Bitbucket remote:
git remote add $1 https://bitbucket.org/$2.git;
git ra jsmith jsmith/prj
25. PRO ALIASES & PROMPT
Get all the alias goodness on Bitbucket
http://bit.do/git-aliases
31. POWERS OF INVISIBILITY
Hide files from
Different from .gitignore, it hides committed files
git update-index --assume-unchanged <file>
very useful with git-svn
32. POWERS OF INVISIBILITY
Hide files from
Revert it with:
git update-index --no-assume-unchanged <file>
remember to add --no
33. POWERS OF INVISIBILITY
List assumed unchanged files
git ls-files -v | grep ^h
Useful as alias (see alias list from before)
37. PRO ALIASES & PROMPT
A word on terminology
What do ours and theirs mean when solving conflicts?
Current checked
out branch
!!!
--ours
38. PRO ALIASES & PROMPT
A word on terminology
What do ours and theirs mean when solving conflicts?
Current checked
out branch
!!!
--ours
Commit coming in
(i.e. via merge)
!!!
--theirs
39. PRO ALIASES & PROMPT
A word on terminology
What do ours and theirs mean when solving conflicts?
Current checked
out branch
!!!
--ours
Commit coming in
(i.e. via merge)
!!!
--theirs
40. PRO ALIASES & PROMPT
Basics for easy conflict resolution
The common commands are:
$ git checkout --ours/--theirs <file>
Check back out our own/their own version of the file
41. PRO ALIASES & PROMPT
Basics for easy conflict resolution
The common commands are:
$ git checkout --ours/--theirs <file>
Check back out our own/their own version of the file
$ git add <file>
Add the change to the index will resolve the conflict
42. PRO ALIASES & PROMPT
Aliases for easy conflict resolution
Add these to [alias] in .gitconfig:
git checkout --ours $@ && git add $@;
43. PRO ALIASES & PROMPT
Aliases for easy conflict resolution
Add these to [alias] in .gitconfig:
ours = "!f() {
git checkout --ours $@ && git add $@;
}; f"
44. PRO ALIASES & PROMPT
rerere resolve!
Reuse Recorded Resolution will help you when
dealing with repetitive and similar merge conflicts.
$ git config --global rerere.enabled true
Turns it on and forget about it
45. PRO ALIASES & PROMPT
Sample output rerere
$ git add hello.rb
$ git commit
Recorded resolution for 'hello.rb'.
[master 68e16e5] Merge branch 'i18n'
46. PRO ALIASES & PROMPT
Sample output rerere
$ git add hello.rb
$ git commit
Recorded resolution for 'hello.rb'.
[master 68e16e5] Merge branch 'i18n'
Auto-merging hello.rb
CONFLICT (content): Merge conflict in hello.rb
Resolved 'hello.rb' using previous resolution.
49. POLISH YOUR CODE
What is a rebase?
It’s a way to replay commits, one by one,
on top of a branch
MASTER
FEATURE
50. POLISH YOUR CODE
What is a rebase?
It’s a way to replay commits, one by one,
on top of a branch
MASTER
FEATURE
51. POLISH YOUR CODE
What is a rebase?
It’s a way to replay commits, one by one,
on top of a branch
MASTER
FEATURE
52. POLISH YOUR CODE
What is a rebase?
It’s a way to replay commits, one by one,
on top of a branch
MASTER
FEATURE
53. POLISH YOUR CODE
What is a rebase?
It’s a way to replay commits, one by one,
on top of a branch
MASTER
FEATURE
Don’t use!
54. POLISH YOUR CODE
What is a rebase?
Correct way to use rebase to update a
feature branch
MASTER
FEATURE
55. POLISH YOUR CODE
What is a rebase?
Correct way to use rebase to update a
feature branch
MASTER
FEATURE
56. POLISH YOUR CODE
What is an --interactive rebase?
It’s a way to replay commits, one by one,
deciding interactively what to do with each
PICK!
SQUASH
REWORD!
FIXUP
EDIT !
EXEC
57. POLISH YOUR CODE
--autosquash
Automatically modify the todo list of
rebase --interactive by annotating commits
$ git config --global rebase.autosquash true
Turns on the feature
58. POLISH YOUR CODE
--autosquash
You can prepend commit messages with:
git commit -m “squash! …"
git commit -m “fixup! …"
git commit -m “reword! …"
etc…
Rebase task list will be then prepopulated
59. CUSTOMARY
WARNING!
rebase rewrites history!
Treat this power with great care.
Only rewrite history of local branches or…
62. PREVENT TAMPERING
Lock down your repo
Edit .git/config in the [receive] section:
# no rewriting history
denyNonFastForwards = true
!
# no deleting history
denyDeletes = true
!
# check object consistency
fsckObjects = true
63. Reject force push,
Luke
Git project has already an update hook
‘update-paranoid’ that is designed to
reject history rewriting updates
http://bit.do/update-paranoid
66. PREVENT TAMPERING
Impersonating Authors is easy
with
$ git commit -m "I'm Luke"
$ git commit --author "Elvis <elvis@graceland.net>" -m "I'm elvis"
commit a9f0967cba236465d6cb68247..
Author: Elvis <elvis@graceland.net>
Date: Mon Apr 22 18:06:35 2013 -0500
!
I'm Elvis
!
commit d6eb7572cbb4bdd8e2aaa5c90..
Author: Luke <luke@tatooine.com>
Date: Mon Apr 22 18:04:54 2013 -0500
!
I'm Luke
67. PREVENT TAMPERING
Finally you can sign/verify tags
git tag -s <tag_name> -m “message”
Sign a tag with your GPG key
git tag -v <tag_name>
Verifies that the signature is valid
69. PREVENT TAMPERING
Aside on GPG
The GNU Privacy Guard
GnuPG allows to encrypt and sign your data and
communication, features a versatile key management system.
71. PREVENT TAMPERING
Harden up by signing things
Sample gpg commands to get you started:
gpg --gen-key
Generate your GPG keys
72. PREVENT TAMPERING
Harden up by signing things
Sample gpg commands to get you started:
gpg --gen-key
Generate your GPG keys
gpg -k
List your keys
73. PREVENT TAMPERING
Harden up by signing things
Sample gpg commands to get you started:
gpg --gen-key
Generate your GPG keys
gpg -k
List your keys
gpg -a --export <keyid>
Export your key
74. PREVENT TAMPERING
Hide files in raw objects
The way the Linux kernel hackers do it
git hash-object -w <file>
75. PREVENT TAMPERING
Hide files in raw objects
The way the Linux kernel hackers do it
actually writes into the object db
git hash-object -w <file>
76. PREVENT TAMPERING
Hide files in raw objects
The way the Linux kernel hackers do it
actually writes into the object db
git hash-object -w <file>
Remember to associate a tag to
it or it will be garbage collected
77. PREVENT TAMPERING
Store your signature in
Simple! Add a tag referencing your public key
gpg -a --export <keyid> |
git hash-object -w --stdin
Store your public key in a raw object
78. PREVENT TAMPERING
Store your signature in
Simple! Add a tag referencing your public key
gpg -a --export <keyid> |
git hash-object -w --stdin
Store your public key in a raw object
git tag nicks-key 65704f3…
Tag the raw object with a label
79. PREVENT TAMPERING
Store your signature in
Simple! Add a tag referencing your public key
gpg -a --export <keyid> |
git hash-object -w --stdin
Store your public key in a raw object
git tag nicks-key 65704f3…
Tag the raw object with a label
raw object id
80. PREVENT TAMPERING
Import other public keys
git cat-file -p tims-key | gpg --import
Import a GPG key from a tag
81. PREVENT TAMPERING
Finally you can sign/verify tags
git tag -s <tag_name> -m “message”
Sign a tag with your GPG key
git tag -v <tag_name>
Verifies that the signature is valid
94. POWERS OF INVISIBILITY
Hide files from
• Level One
• Level Two
• Level Two
• Level Two
• Level One
CODE FONT:
<html xmlns="http://www.w3.org/1999/xhtml">
95. POWERS OF INVISIBILITY
Page title here
• Level One
• Level Two
• Level Two
• Level Two
• Level One
96. Page title here
• Level One
• Level Two
• Level Two
• Level Two
• Level One
97. Page title here
Page Title Here
• Level One
• Level Two
• Level Two
• Level Two
• Level One
98. Page title here
• Level One
• Level Two
• Level Two
• Level Two
• Level One
106. Type Quote Here And Move Both Quotation
Marks To The Beginning And End Of The
Quote. Lorem Ipsum Dolor Sit Amet, Conse
Cetur Ading Elit.
DAVID HANDLY, GLOBOCHEM
”
“