Git Down, Git On Up: Practical Examples of Intermediate Git Techniques
-
Upload
siena-aguayo -
Category
Software
-
view
197 -
download
4
Transcript of Git Down, Git On Up: Practical Examples of Intermediate Git Techniques
![Page 1: Git Down, Git On Up: Practical Examples of Intermediate Git Techniques](https://reader033.fdocuments.in/reader033/viewer/2022061618/55c5ec5abb61ebf3158b46c1/html5/thumbnails/1.jpg)
GIT DOWN, GIT ON UPPRACTICAL EXAMPLES OF INTERMEDIATE GIT TECHNIQUES
Siena AguayoIndiegogo Software Engineer & Hackbright AlumnaApril 23rd, 2014
![Page 2: Git Down, Git On Up: Practical Examples of Intermediate Git Techniques](https://reader033.fdocuments.in/reader033/viewer/2022061618/55c5ec5abb61ebf3158b46c1/html5/thumbnails/2.jpg)
ACKNOWLEDGMENTS
@the_zenspider for the title of this talk
![Page 3: Git Down, Git On Up: Practical Examples of Intermediate Git Techniques](https://reader033.fdocuments.in/reader033/viewer/2022061618/55c5ec5abb61ebf3158b46c1/html5/thumbnails/3.jpg)
MERGING VS. REBASING
![Page 4: Git Down, Git On Up: Practical Examples of Intermediate Git Techniques](https://reader033.fdocuments.in/reader033/viewer/2022061618/55c5ec5abb61ebf3158b46c1/html5/thumbnails/4.jpg)
THINGS TO KNOW• Local copy: a somewhat-secret copy of the files of the
remote repository that lives in the .git folder of your repo
• Working tree/working directory: the files you are actually modifying in your text editor
![Page 5: Git Down, Git On Up: Practical Examples of Intermediate Git Techniques](https://reader033.fdocuments.in/reader033/viewer/2022061618/55c5ec5abb61ebf3158b46c1/html5/thumbnails/5.jpg)
GIT MERGE
Did you know…?
$ git pull is actually two commands:
$ git fetch
$ git merge FETCH_HEAD
$ git fetch updates your local repository (not your working tree) with changes from the remote branch, then $ git merge merges your local repo with the changes you have made to your working tree, creating a new commit that has two parents.
![Page 6: Git Down, Git On Up: Practical Examples of Intermediate Git Techniques](https://reader033.fdocuments.in/reader033/viewer/2022061618/55c5ec5abb61ebf3158b46c1/html5/thumbnails/6.jpg)
GIT MERGE
A---B---C topic
/
D---E---F---G master
Becomes…
A---B---C topic
/ \
D---E---F---G---H master
H is a new, merge commitwith two parents!
C G
H
![Page 7: Git Down, Git On Up: Practical Examples of Intermediate Git Techniques](https://reader033.fdocuments.in/reader033/viewer/2022061618/55c5ec5abb61ebf3158b46c1/html5/thumbnails/7.jpg)
GIT REBASE
(my_feature_branch) $ git rebase master
Replays your changes on top of master so that your commits are always on top. Does not create a merge commit and your history is streamlined.
But remember $ git pull fetches then merges…?
$ git pull –-rebase will fetch and then rebase instead!
![Page 8: Git Down, Git On Up: Practical Examples of Intermediate Git Techniques](https://reader033.fdocuments.in/reader033/viewer/2022061618/55c5ec5abb61ebf3158b46c1/html5/thumbnails/8.jpg)
GIT REBASE
A---B---C topic
/
D---E---F---G master
Becomes…
A'--B'--C' topic
/
D---E---F---G master No new commit, history is in a single line (each commit only has one parent)
![Page 9: Git Down, Git On Up: Practical Examples of Intermediate Git Techniques](https://reader033.fdocuments.in/reader033/viewer/2022061618/55c5ec5abb61ebf3158b46c1/html5/thumbnails/9.jpg)
INTERACTIVE REBASE TO THE RESCUE
commit 9f82kh
Author: Siena Aguayo [email protected]
Omg I fixed it
commit jf8djb
Author: Siena Aguayo [email protected]
What is happening
commit 0g1bdi
Author: Siena Aguayo [email protected]
Stuff is broken
Does your commit history look like this?
$ git log
![Page 10: Git Down, Git On Up: Practical Examples of Intermediate Git Techniques](https://reader033.fdocuments.in/reader033/viewer/2022061618/55c5ec5abb61ebf3158b46c1/html5/thumbnails/10.jpg)
INTERACTIVE REBASE TO THE RESCUE
$ git rebase –i HEAD~3
vim
pick 9f82kh Stuff is broken
pick jf8djb What is happening
pick 0g1bdi Omg I fixed it
![Page 11: Git Down, Git On Up: Practical Examples of Intermediate Git Techniques](https://reader033.fdocuments.in/reader033/viewer/2022061618/55c5ec5abb61ebf3158b46c1/html5/thumbnails/11.jpg)
INTERACTIVE REBASE TO THE RESCUE
$ git rebase –i HEAD~3
vim
pick 9f82kh Stuff is broken
squash jf8djb What is happening
squash 0g1bdi Omg I fixed it
![Page 12: Git Down, Git On Up: Practical Examples of Intermediate Git Techniques](https://reader033.fdocuments.in/reader033/viewer/2022061618/55c5ec5abb61ebf3158b46c1/html5/thumbnails/12.jpg)
INTERACTIVE REBASE TO THE RESCUE
vim
# This is a combination of 4 commits.
# The first commit's message is:
…
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
![Page 13: Git Down, Git On Up: Practical Examples of Intermediate Git Techniques](https://reader033.fdocuments.in/reader033/viewer/2022061618/55c5ec5abb61ebf3158b46c1/html5/thumbnails/13.jpg)
INTERACTIVE REBASE TO THE RESCUE
vim
I fixed that thing and here is a wonderfully detailed commit message.
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
![Page 14: Git Down, Git On Up: Practical Examples of Intermediate Git Techniques](https://reader033.fdocuments.in/reader033/viewer/2022061618/55c5ec5abb61ebf3158b46c1/html5/thumbnails/14.jpg)
IF YOU SCREW IT UP
$ git reflog
e94a244 HEAD@{0}: checkout: moving from master to gittalk
e94a244 HEAD@{1}: rebase -i (finish): returning to refs/heads/master
e94a244 HEAD@{2}: rebase -i (start): checkout HEAD~2
e94a244 HEAD@{3}: cherry-pick: updated readme to include link to Vimeo video
![Page 15: Git Down, Git On Up: Practical Examples of Intermediate Git Techniques](https://reader033.fdocuments.in/reader033/viewer/2022061618/55c5ec5abb61ebf3158b46c1/html5/thumbnails/15.jpg)
OTHER GIT COMMANDS
![Page 16: Git Down, Git On Up: Practical Examples of Intermediate Git Techniques](https://reader033.fdocuments.in/reader033/viewer/2022061618/55c5ec5abb61ebf3158b46c1/html5/thumbnails/16.jpg)
GIT STASH
Allows you to push your current changes onto a stash stack so that you can do something (like pull or checkout) without committing your changes yet
$ git stash save “working on some stuff”
$ git stash list
stash@{0}: On master: working on some stuff
stash@{1}: WIP on (no branch): 8684246
stash@{2}: On master: stuff
stash@{3}: On master: acceptance tests for that thing
$ git stash apply stash@{2}
$ git stash pop
![Page 17: Git Down, Git On Up: Practical Examples of Intermediate Git Techniques](https://reader033.fdocuments.in/reader033/viewer/2022061618/55c5ec5abb61ebf3158b46c1/html5/thumbnails/17.jpg)
GIT CHERRY-PICK
Take a commit from another branch and stick it into your current branch
Commit 9283fj is in some other branch
$ git checkout master
$ git cherry-pick 9283fj
Now it’s in master too!
![Page 18: Git Down, Git On Up: Practical Examples of Intermediate Git Techniques](https://reader033.fdocuments.in/reader033/viewer/2022061618/55c5ec5abb61ebf3158b46c1/html5/thumbnails/18.jpg)
Uses binary search to help you figure out what commit introduced a bug
$ git bisect start
$ git bisect good 9193jfp
$ git bisect bad 09480f
…
$ git bisect reset
GIT BISECT
good
bad
Good or bad?
![Page 19: Git Down, Git On Up: Practical Examples of Intermediate Git Techniques](https://reader033.fdocuments.in/reader033/viewer/2022061618/55c5ec5abb61ebf3158b46c1/html5/thumbnails/19.jpg)
OTHER GIT RESOURCES
![Page 20: Git Down, Git On Up: Practical Examples of Intermediate Git Techniques](https://reader033.fdocuments.in/reader033/viewer/2022061618/55c5ec5abb61ebf3158b46c1/html5/thumbnails/20.jpg)
GIT PAIR
A nifty little script from Pivotal Labs that lets you add multiple authors to a commit. Just add author info to a text file.
$ git pair sa sc
global: user.name Siena Aguayo
local: user.name Siena Aguayo & Stella Cotton
NOTE: Overriding global user.email setting with local.
global: user.email [email protected]
local: user.email [email protected]
local: user.initials sa sc
![Page 21: Git Down, Git On Up: Practical Examples of Intermediate Git Techniques](https://reader033.fdocuments.in/reader033/viewer/2022061618/55c5ec5abb61ebf3158b46c1/html5/thumbnails/21.jpg)
BASH SCRIPTS
git-completion
• Tab completion for git commands, branch names, etc.
git-prompt
• Show which branch you are on in your prompt, e.g.siena@Siena-MBP ocr-jpn (master) $
![Page 22: Git Down, Git On Up: Practical Examples of Intermediate Git Techniques](https://reader033.fdocuments.in/reader033/viewer/2022061618/55c5ec5abb61ebf3158b46c1/html5/thumbnails/22.jpg)
GITHUG
Play a fun game to take your Git skills to the next level!
Just clone the repo and run $ githug play
https://github.com/Gazler/githug
![Page 23: Git Down, Git On Up: Practical Examples of Intermediate Git Techniques](https://reader033.fdocuments.in/reader033/viewer/2022061618/55c5ec5abb61ebf3158b46c1/html5/thumbnails/23.jpg)