Date post: | 15-Jul-2015 |
Category: |
Technology |
Upload: | nicola-paolucci |
View: | 82 times |
Download: | 0 times |
NICOLA PAOLUCCI • DEVELOPER INSTIGATOR • • @DURDN
The business case for GitConcepts and techniques to convert you
into a master of the DVCS craft
Becoming a Git Master
C O N F L I C T R E S O L U T I O N T I P S
H I D I N G S T U F F
Here you’ll learn:
P O L I S H Y O U R C O D E
P R E V E N T TA M P E R I N G
P R O J E C T D E P E N D E N C I E S
P R O A L I A S E S & P R O M P T
P R O A L I A S E S & P R O M P T
Everyone has their favorite, but!Liquid prompt is awesome
http://bit.do/liquid-prompt
P R O A L I A S E S & P R O M P T
Everyone has their favorite, but!Liquid prompt is awesome
http://bit.do/liquid-prompt
P R O A L I A S E S & P R O M P T
Basic Alias FormVery 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
P R O A L I A S E S & P R O M P T
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
P R O A L I A S E S & P R O M P T
For multiple commands or complex parameters use a bash function!
You can escape to a shell with ! like this:
my_alias = "!f() { <command> }; f”
P R O A L I A S E S & P R O M P T
Some useful shortcuts and variablesMore in any bash manual
$@ - all command line parameters passed
$1 - first command line parameter
$2 - second command line parameter
P R O A L I A S E S & P R O M P T
What can you do with this?Cool cool things, for example add a Bitbucket remote:
git remote add $1 https://bitbucket.org/$2.git;
P R O A L I A S E S & P R O M P T
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;
P R O A L I A S E S & P R O M P T
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
P R O A L I A S E S & P R O M P T
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
P R O A L I A S E S & P R O M P T
Get all the alias goodness on Bitbuckethttp://bit.do/git-aliases
Hide files fromDifferent from .gitignore, it hides committed files
P O W E R S O F I N V I S I B I L I T Y
git update-index --assume-unchanged <file>
very useful with git-svn
Hide files fromRevert it with:
P O W E R S O F I N V I S I B I L I T Y
git update-index --no-assume-unchanged <file>
remember to add --no
P O W E R S O F I N V I S I B I L I T Y
List assumed unchanged files
git ls-files -v | grep ^hUseful as alias (see alias list from before)
P R O A L I A S E S & P R O M P T
A word on terminology
Current checked out branch
--ours
What do ours and theirs mean when solving conflicts?
Commit coming in (i.e. via merge)
--theirs
P R O A L I A S E S & P R O M P T
Basics for easy conflict resolutionThe 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
P R O A L I A S E S & P R O M P T
Aliases for easy conflict resolutionAdd these to [alias] in .gitconfig:
git checkout --ours $@ && git add $@;
P R O A L I A S E S & P R O M P T
Aliases for easy conflict resolutionAdd these to [alias] in .gitconfig:
ours = "!f() { \ \ }; f" git checkout --ours $@ && git add $@;
P R O A L I A S E S & P R O M P T
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
P R O A L I A S E S & P R O M P T
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.
P O L I S H Y O U R C O D E
What is a rebase?It’s a way to replay commits, one by one,
on top of a branch
MASTER
FEATURE
P O L I S H Y O U R C O D E
What is a rebase?It’s a way to replay commits, one by one,
on top of a branch
MASTER
FEATURE
P O L I S H Y O U R C O D E
What is a rebase?It’s a way to replay commits, one by one,
on top of a branch
MASTER
FEATURE
Don’t use!
P O L I S H Y O U R C O D E
What is a rebase?Correct way to use rebase to update a
feature branch
MASTER
FEATURE
P O L I S H Y O U R C O D E
What is a rebase?Correct way to use rebase to update a
feature branch
MASTER
FEATURE
P O L I S H Y O U R C O D E
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
P O L I S H Y O U R C O D E
--autosquashAutomatically modify the todo list of
rebase --interactive by annotating commits
$ git config --global rebase.autosquash true Turns on the feature
P O L I S H Y O U R C O D E
--autosquashYou 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
CUSTOMARY WARNING!
rebase rewrites history!
Treat this power with great care. Only rewrite history of local branches or…
P R E V E N T TA M P E R I N G
Lock down your repo
# no rewriting history denyNonFastForwards = true
# no deleting history denyDeletes = true
# check object consistency fsckObjects = true
Edit .git/config in the [receive] section:
Reject force push,Git project has already an update hook ‘update-paranoid’ that is designed to
reject history rewriting updates
Luke
http://bit.do/update-paranoid
P R E V E N T TA M P E R I N G
Impersonating Authors is easy with
$ git commit -m "I'm Luke" $ git commit --author "Elvis <[email protected]>" -m "I'm elvis" commit a9f0967cba236465d6cb68247.. Author: Elvis <[email protected]> Date: Mon Apr 22 18:06:35 2013 -0500
I'm Elvis
commit d6eb7572cbb4bdd8e2aaa5c90.. Author: Luke <[email protected]> Date: Mon Apr 22 18:04:54 2013 -0500
I'm Luke
P R E V E N T TA M P E R I N G
Solution: 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
P R E V E N T TA M P E R I N G
Aside on GPGThe GNU Privacy Guard
GnuPG allows to encrypt and sign your data and communication, features a versatile key management system.
P R E V E N T TA M P E R I N G
Harden up by signing thingsSample gpg commands to get you started:
gpg --gen-keyGenerate your GPG keys
gpg -kList your keys
gpg -a --export <keyid>Export your key
P R E V E N T TA M P E R I N G
Hide files in raw objects
actually writes into the object db
git hash-object -w <file>
Remember to associate a tag to it or it will be garbage collected
P R E V E N T TA M P E R I N G
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
P R E V E N T TA M P E R I N G
Import other public keys
git cat-file -p tims-key | gpg --import
Import a GPG key from a tag
P R E V E N T TA M P E R I N G
Now 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
G I T A N D P R O J E C T D E P E N D E N C I E S
I’ll give you an incomplete list of examples!
Java
Nodejs
Javascript
Python Pip easy-install
Ruby
G I T A N D P R O J E C T D E P E N D E N C I E S
I’ll give you an incomplete list of examples! (2)
C#
C++ c-make
Objective C
PHP
Go godep
G I T A N D P R O J E C T D E P E N D E N C I E S
•Android Repo (http://bit.do/android-repo)•Repobuild (chrisvana / repobuild)•Chromium depot_tools (http://bit.do/depot-tools)•Facebook Buck (http://facebook.github.io/buck/)•Twitter Pants (http://bit.do/twitter-pants)
For example you can check out:
C O N F L I C T R E S O L U T I O N T I P S
H I D I N G S T U F F
Today we covered:
P O L I S H Y O U R C O D E
P R E V E N T TA M P E R I N G
P R O J E C T D E P E N D E N C I E S
P R O A L I A S E S & P R O M P T