SlideShare una empresa de Scribd logo
1 de 57
Descargar para leer sin conexión
How to Really GetHow to Really Get
GitGit
Sunday, February 8, 2015
Susan Tan
@ArcTanSusan
Who am I?
Software Engineer @Piston who uses Python and git
A New-Yorker-who-moved-to-San-Francisco
Also Piston is .hiring
I. Git SetupI. Git Setup
Git Configs: AliasesGit Configs: Aliases
[alias]
st = status
ci = commit
br = branch
co = checkout
df = diff
lg = log -p
$ git st
# On branch master
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# _posts/2009-02-06-helpful-command-aliases.textile
nothing added to commit but untracked files present (use "git add" to track)
In ~/.gitconfig, put this here:
Git Configs: ColorsGit Configs: Colors
[color "status"]
added = magenta
changed = yellow
untracked = cyan
In ~/.gitconfig, put this:
Git Configs:Git Configs:
Tab AutocompletionTab Autocompletion
1. Follow instructions for your OS.
2. Then you can use auto tab completion on long commands
here
$ git chec<tab>
Git Configs:Git Configs:
A Useful Bash PromptA Useful Bash Prompt
https://github.com/bobthecow/git-flow-completion/wiki/Install-Bash-git-completion
A useful prompt shows
current branch
current directory
current virtualenv
status of working directory
Who is this talk for?
You already know the basics of git, but you still make
mistakes (well, so does everyone)
Common git commands you already know:
git add
git status
git push origin
git fetch origin
You want to know how to deal with mistakes
Common git commands you'll learn about:
git rebase
git reset
git reflog
git revert
This Should Look FamiliarThis Should Look Familiar
Source: http://git-scm.com/book/ch1-3.html
This should be familiar, tooThis should be familiar, too
This may be familiar, tooThis may be familiar, too
This should be familiar, too -- Collaboration with git.This should be familiar, too -- Collaboration with git.
Source: http://nvie.com/posts/a-successful-git-branching-model/
II. Mistakes and howII. Mistakes and how
to fix themto fix them
"People think computers will keep them from making mistakes.
They're wrong. With computers you make mistakes faster."
--Adam Osborn
Source: http://justinhileman.info/article/git-pretty/git-pretty.pdf
git rebasegit rebase
Why use rebase?
1. git rebase to keep a branch updated
2. git rebase --interactive flag to change history
git rebase: The Simplest Usagegit rebase: The Simplest Usage
Note: "master" here means remote upstream's master branch.
git rebase: The Simplest Usagegit rebase: The Simplest Usage
What if your personal branch "develop" needs to rebaseWhat if your personal branch "develop" needs to rebase
against a feature branch shared by your team members?against a feature branch shared by your team members?
Note: "master" here means remote upstream repo's master branch.
What if your personal branch "develop" needs to rebaseWhat if your personal branch "develop" needs to rebase
against a feature branch shared by your team members?against a feature branch shared by your team members?
Note: "master" here means remote upstream repo's master branch.
git rebase master/feature develop
git rebase --onto master feature develop
Note: "master" here means remote upstream repo's master branch.
OR
git rebasegit rebase
git rebase <remote_repo>/<remote_branch> <your_branch_name>
git rebase --onto <first_this> <then_this> <last>
Syntax for git rebase
What if the feature branch needs to rebase against aWhat if the feature branch needs to rebase against a
upstream repo's master branch shared by everyone?upstream repo's master branch shared by everyone?
Note: "master" here means remote upstream repo's master branch.
What if the feature branch needs to rebase against aWhat if the feature branch needs to rebase against a
upstream repo's master branch shared by everyone?upstream repo's master branch shared by everyone?
Note: "master" here means remote upstream repo's master branch.
Rebase ConflictsRebase Conflicts
Rebase Conflicts require manual fixesRebase Conflicts require manual fixes
(because git isn't clever enough to fix conflicts)
1. Locate conflict markers (<<<<<<) and
make edits to resolve
2. Resolve a conflict in each file with git
add <filename>
3. ​git rebase --continue
4. Alternatively, you can undo the git
rebase with git rebase --abort
Fixing git rebase conflicts is notFixing git rebase conflicts is not
always the right solutionalways the right solution
git checkout master
git branch -D feature
git fetch master
git checkout -b feature master/feature
git checkout -b develop_v2
git merge develop_v1
git branch -D develop_v1
git fetch master
git checkout [YOUR BRANCH]
git rebase --onto master/feature [commit]
OR
Different computers, sameDifferent computers, same
branchbranch
git fetch origin && git rebase origin/<MY_BRANCH>
Note: "origin" is your personal cloned copy of an upstream master
repo
git pull --rebase
Or, equivalently
git rebase --interactive <HASH>
or
git rebase --interactive HEAD^
Defn: To re-order, edit, squash, or remove many
commits at once
git rebase -i HEAD~5
Squashing commitsSquashing commits
git resetgit reset
Defn: Reset current HEAD to the specified state
git reset --soft HEAD^
Defn: Set files from previous commit onto staging area. HEAD
points to the previous commit. This leaves all your changed files
as "Changes to be committed".
git reset --soft HEAD^
git reset --hard HEAD^
Defn: Abandon everything since your last commit. HEAD points
to the previous commit. Nothing is in staging. Use with great
caution
git refloggit reflog
Defn: shows all the commits and actions on your machine that has
ever happened such as branch switches, rebases, resets, branch
deletions, cherry-picks, reverts.
git reflog git reflog --grep="Revert"
How to make git reflog more usefulHow to make git reflog more useful
git reflog --all --date=iso
You can undo a hard reset with the help of git reflogYou can undo a hard reset with the help of git reflog
git reset --hard HEAD^^ to remove the last 3 commits
You can undo a hard reset with git reflog + git reset --hardYou can undo a hard reset with git reflog + git reset --hard
git reset --hard a64b0f2 to restore branch to previous stategit reset --hard a64b0f2 to restore branch to previous state
Why use git reflog?Why use git reflog?
You lost commits when you did a git reset --hard
You squashed too many commits into 1 commit, so you
want to undo git rebase -i
You accidentally deleted branches and want to restore
them
Summary: Use reflog to look up old lost commits
Use cases for git reflogUse cases for git reflog
Look up a commit hash. Then either
create a new (un-named) branch out of this commit
git checkout -b <COMMIT_HASH>
reset your branch to a previous state
git reset --hard <COMMIT_HASH>
git reset --soft <COMMIT_HASH>
cherrypick that lost commit on top of your branch
git cherry-pick <COMMIT_HASH>
How long does theHow long does the
output of reflog last?output of reflog last?
Hanging commits are removed from the local repository by
garbage collection (gc) or by manual removal. Default is 30
days.
[gc]
reflogExpire = never
reflogExpireUnreachable = never
git revert 638351801cd802d6e0c4e601db1eca801dd58936
Defn: Makes a revert commit with a message that states the
specified commit is reverted
git revert <HASH>
Defn: Revert changes specified by 4th last commit away
from HEAD and create a new commit with reverted changes.
git revert HEAD~3
git revert --continue
Continue after resolving conflicts
git revert --abort
Cancel operation and return to pre-sequence state
git revert --quit
Can be used to start over after a failed cherry-pick or revert
Git revert conflictsGit revert conflicts
When to use git reset vs. git revertWhen to use git reset vs. git revert
Permanent MistakesPermanent Mistakes
Permanent MistakesPermanent Mistakes
git push -f origin <REMOTE>
SummarySummary
If you run into git problems, the solution is most likely to
use one of these --
git rebase
git reset
git reflog
git revert
III. Automate gitIII. Automate git
Problem: Repetitive branch deletingProblem: Repetitive branch deleting
vagrant@precise64:~/work/savage$ git push origin :73997184
To git@github.com:onceuponatimeforever/savage.git
- [deleted] 73997184
vagrant@precise64:~/work/savage$ git push origin :76321732-on-mast
To git@github.com:onceuponatimeforever/savage.git
- [deleted] 76321732-on-master
vagrant@precise64:~/work/savage$ git push origin :77910316
To git@github.com:onceuponatimeforever/savage.git
- [deleted] 77910316
vagrant@precise64:~/work/savage$ git push origin :77910316-bottle
To git@github.com:onceuponatimeforever/savage.git
- [deleted] 77910316-bottle
vagrant@precise64:~/work/savage$ git push origin :77910316-bottle-
To git@github.com:onceuponatimeforever/savage.git
- [deleted] 77910316-bottle-from-scratch
vagrant@precise64:~/work/savage$ git push origin :2.0/master
IPython notebook supports gitIPython notebook supports git
Solution: IPython notebook scriptSolution: IPython notebook script
Problem: Fetch & rebase repetitionsProblem: Fetch & rebase repetitions
cd <PROJECT>
git fetch upstream
git rebase upstream/master
cd ../<ANOTHER_PROJECT>
git fetch upstream
git rebase upstream/master
# And again
....
Solution: IPython notebook scriptSolution: IPython notebook script
list_of_projects = ['ipython', 'oh-mainline']
def update(project):
%cd {project}
!git checkout master
!git fetch upstream
!git rebase upstream/master
!git push origin master
%cd ..
print "Done git rebasing this repoo: ", {project}
for project in list_of_projects:
update(list_of_projects[project])
print "---------------------------------"
Solution: IPython notebook scriptSolution: IPython notebook script
Thanks! Q&A Time.Thanks! Q&A Time.

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

git fail --force (make it up with your pull requests)
git fail --force (make it up with your pull requests)git fail --force (make it up with your pull requests)
git fail --force (make it up with your pull requests)
 
Introduction to Git and GitHub
Introduction to Git and GitHubIntroduction to Git and GitHub
Introduction to Git and GitHub
 
Intro to git and git hub
Intro to git and git hubIntro to git and git hub
Intro to git and git hub
 
Version Control & Git
Version Control & GitVersion Control & Git
Version Control & Git
 
Git and git workflow best practice
Git and git workflow best practiceGit and git workflow best practice
Git and git workflow best practice
 
Advanced Git
Advanced GitAdvanced Git
Advanced Git
 
Git, from the beginning
Git, from the beginningGit, from the beginning
Git, from the beginning
 
Git Flow and JavaScript Coding Style
Git Flow and JavaScript Coding StyleGit Flow and JavaScript Coding Style
Git Flow and JavaScript Coding Style
 
Introduction to Git (Greg Lonnon)
Introduction to Git (Greg Lonnon)Introduction to Git (Greg Lonnon)
Introduction to Git (Greg Lonnon)
 
Git training
Git trainingGit training
Git training
 
Advanced Git Tutorial
Advanced Git TutorialAdvanced Git Tutorial
Advanced Git Tutorial
 
Git Distributed Version Control System
Git   Distributed Version Control SystemGit   Distributed Version Control System
Git Distributed Version Control System
 
Git Introduction Tutorial
Git Introduction TutorialGit Introduction Tutorial
Git Introduction Tutorial
 
Git Tricks
Git TricksGit Tricks
Git Tricks
 
Git tutorial
Git tutorialGit tutorial
Git tutorial
 
Git Magic: Versioning Files like a Boss
Git Magic: Versioning Files like a BossGit Magic: Versioning Files like a Boss
Git Magic: Versioning Files like a Boss
 
Git internals
Git internalsGit internals
Git internals
 
Git inter-snapshot public
Git  inter-snapshot publicGit  inter-snapshot public
Git inter-snapshot public
 
Git tutorial
Git tutorialGit tutorial
Git tutorial
 
Git Version Control System
Git Version Control SystemGit Version Control System
Git Version Control System
 

Similar a How to Really Get Git

Git-ing out of your git messes
Git-ing out of  your git messesGit-ing out of  your git messes
Git-ing out of your git messesKatie Sylor-Miller
 
Honestly Git Playground 20190221
Honestly Git Playground 20190221Honestly Git Playground 20190221
Honestly Git Playground 20190221Shinho Kang
 
Introduction to Git for Artists
Introduction to Git for ArtistsIntroduction to Git for Artists
Introduction to Git for ArtistsDavid Newbury
 
Improving your workflow with git
Improving your workflow with gitImproving your workflow with git
Improving your workflow with gitDídac Ríos
 
Mastering git - Workflow
Mastering git - WorkflowMastering git - Workflow
Mastering git - WorkflowTahsin Abrar
 
Git Started With Git
Git Started With GitGit Started With Git
Git Started With GitNick Quaranto
 
Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?9 series
 
Git Memento of basic commands
Git Memento of basic commandsGit Memento of basic commands
Git Memento of basic commandsZakaria Bouazza
 
GIT in a nutshell
GIT in a nutshellGIT in a nutshell
GIT in a nutshellalignan
 
Git - Get Ready To Use It
Git - Get Ready To Use ItGit - Get Ready To Use It
Git - Get Ready To Use ItDaniel Kummer
 
Git Anti-Patterns: How To Mess Up With Git and Love it Again
Git Anti-Patterns: How To Mess Up With Git and Love it AgainGit Anti-Patterns: How To Mess Up With Git and Love it Again
Git Anti-Patterns: How To Mess Up With Git and Love it AgainLemi Orhan Ergin
 

Similar a How to Really Get Git (20)

Git github
Git githubGit github
Git github
 
Git
GitGit
Git
 
Git-ing out of your git messes
Git-ing out of  your git messesGit-ing out of  your git messes
Git-ing out of your git messes
 
Honestly Git Playground 20190221
Honestly Git Playground 20190221Honestly Git Playground 20190221
Honestly Git Playground 20190221
 
Git basics 2
Git basics 2Git basics 2
Git basics 2
 
Introduction to Git for Artists
Introduction to Git for ArtistsIntroduction to Git for Artists
Introduction to Git for Artists
 
Wokshop de Git
Wokshop de Git Wokshop de Git
Wokshop de Git
 
Git tutorial
Git tutorialGit tutorial
Git tutorial
 
Improving your workflow with git
Improving your workflow with gitImproving your workflow with git
Improving your workflow with git
 
GIT Basics
GIT BasicsGIT Basics
GIT Basics
 
Mastering git - Workflow
Mastering git - WorkflowMastering git - Workflow
Mastering git - Workflow
 
Git Started With Git
Git Started With GitGit Started With Git
Git Started With Git
 
Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?
 
Git Memento of basic commands
Git Memento of basic commandsGit Memento of basic commands
Git Memento of basic commands
 
Git and github 101
Git and github 101Git and github 101
Git and github 101
 
GIT in a nutshell
GIT in a nutshellGIT in a nutshell
GIT in a nutshell
 
How to use git without rage
How to use git without rageHow to use git without rage
How to use git without rage
 
Git - Get Ready To Use It
Git - Get Ready To Use ItGit - Get Ready To Use It
Git - Get Ready To Use It
 
GIT_In_90_Minutes
GIT_In_90_MinutesGIT_In_90_Minutes
GIT_In_90_Minutes
 
Git Anti-Patterns: How To Mess Up With Git and Love it Again
Git Anti-Patterns: How To Mess Up With Git and Love it AgainGit Anti-Patterns: How To Mess Up With Git and Love it Again
Git Anti-Patterns: How To Mess Up With Git and Love it Again
 

Más de Susan Tan

Rants and Ruminations From A Job Applicant After 💯 CS Job Interviews in Silic...
Rants and Ruminations From A Job Applicant After 💯 CS Job Interviews in Silic...Rants and Ruminations From A Job Applicant After 💯 CS Job Interviews in Silic...
Rants and Ruminations From A Job Applicant After 💯 CS Job Interviews in Silic...Susan Tan
 
Let's read code: python-requests library
Let's read code: python-requests libraryLet's read code: python-requests library
Let's read code: python-requests librarySusan Tan
 
How to Upgrade to the Newest Shiniest Django Version
How to Upgrade to the Newest Shiniest Django VersionHow to Upgrade to the Newest Shiniest Django Version
How to Upgrade to the Newest Shiniest Django VersionSusan Tan
 
How do I run multiple python apps in 1 command line under 1 WSGI app?
How do I run multiple python apps in 1 command line under 1 WSGI app?How do I run multiple python apps in 1 command line under 1 WSGI app?
How do I run multiple python apps in 1 command line under 1 WSGI app?Susan Tan
 
Let's read code: the python-requests library
Let's read code: the python-requests libraryLet's read code: the python-requests library
Let's read code: the python-requests librarySusan Tan
 
Python In The Browser: Intro to Brython
Python In The Browser: Intro to BrythonPython In The Browser: Intro to Brython
Python In The Browser: Intro to BrythonSusan Tan
 
How to choose an open-source project
How to choose an open-source projectHow to choose an open-source project
How to choose an open-source projectSusan Tan
 

Más de Susan Tan (7)

Rants and Ruminations From A Job Applicant After 💯 CS Job Interviews in Silic...
Rants and Ruminations From A Job Applicant After 💯 CS Job Interviews in Silic...Rants and Ruminations From A Job Applicant After 💯 CS Job Interviews in Silic...
Rants and Ruminations From A Job Applicant After 💯 CS Job Interviews in Silic...
 
Let's read code: python-requests library
Let's read code: python-requests libraryLet's read code: python-requests library
Let's read code: python-requests library
 
How to Upgrade to the Newest Shiniest Django Version
How to Upgrade to the Newest Shiniest Django VersionHow to Upgrade to the Newest Shiniest Django Version
How to Upgrade to the Newest Shiniest Django Version
 
How do I run multiple python apps in 1 command line under 1 WSGI app?
How do I run multiple python apps in 1 command line under 1 WSGI app?How do I run multiple python apps in 1 command line under 1 WSGI app?
How do I run multiple python apps in 1 command line under 1 WSGI app?
 
Let's read code: the python-requests library
Let's read code: the python-requests libraryLet's read code: the python-requests library
Let's read code: the python-requests library
 
Python In The Browser: Intro to Brython
Python In The Browser: Intro to BrythonPython In The Browser: Intro to Brython
Python In The Browser: Intro to Brython
 
How to choose an open-source project
How to choose an open-source projectHow to choose an open-source project
How to choose an open-source project
 

Último

ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
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
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
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
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
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
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024The Digital Insurer
 

Último (20)

ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
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
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
+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...
 
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...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
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, ...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 

How to Really Get Git

  • 1. How to Really GetHow to Really Get GitGit Sunday, February 8, 2015 Susan Tan @ArcTanSusan
  • 2. Who am I? Software Engineer @Piston who uses Python and git A New-Yorker-who-moved-to-San-Francisco Also Piston is .hiring
  • 3.
  • 4. I. Git SetupI. Git Setup
  • 5. Git Configs: AliasesGit Configs: Aliases [alias] st = status ci = commit br = branch co = checkout df = diff lg = log -p $ git st # On branch master # Untracked files: # (use "git add <file>..." to include in what will be committed) # # _posts/2009-02-06-helpful-command-aliases.textile nothing added to commit but untracked files present (use "git add" to track) In ~/.gitconfig, put this here:
  • 6. Git Configs: ColorsGit Configs: Colors [color "status"] added = magenta changed = yellow untracked = cyan In ~/.gitconfig, put this:
  • 7. Git Configs:Git Configs: Tab AutocompletionTab Autocompletion 1. Follow instructions for your OS. 2. Then you can use auto tab completion on long commands here $ git chec<tab>
  • 8. Git Configs:Git Configs: A Useful Bash PromptA Useful Bash Prompt https://github.com/bobthecow/git-flow-completion/wiki/Install-Bash-git-completion A useful prompt shows current branch current directory current virtualenv status of working directory
  • 9. Who is this talk for? You already know the basics of git, but you still make mistakes (well, so does everyone) Common git commands you already know: git add git status git push origin git fetch origin You want to know how to deal with mistakes Common git commands you'll learn about: git rebase git reset git reflog git revert
  • 10. This Should Look FamiliarThis Should Look Familiar Source: http://git-scm.com/book/ch1-3.html
  • 11. This should be familiar, tooThis should be familiar, too
  • 12. This may be familiar, tooThis may be familiar, too
  • 13. This should be familiar, too -- Collaboration with git.This should be familiar, too -- Collaboration with git. Source: http://nvie.com/posts/a-successful-git-branching-model/
  • 14. II. Mistakes and howII. Mistakes and how to fix themto fix them "People think computers will keep them from making mistakes. They're wrong. With computers you make mistakes faster." --Adam Osborn
  • 16. git rebasegit rebase Why use rebase? 1. git rebase to keep a branch updated 2. git rebase --interactive flag to change history
  • 17. git rebase: The Simplest Usagegit rebase: The Simplest Usage Note: "master" here means remote upstream's master branch.
  • 18. git rebase: The Simplest Usagegit rebase: The Simplest Usage
  • 19. What if your personal branch "develop" needs to rebaseWhat if your personal branch "develop" needs to rebase against a feature branch shared by your team members?against a feature branch shared by your team members? Note: "master" here means remote upstream repo's master branch.
  • 20. What if your personal branch "develop" needs to rebaseWhat if your personal branch "develop" needs to rebase against a feature branch shared by your team members?against a feature branch shared by your team members? Note: "master" here means remote upstream repo's master branch.
  • 21. git rebase master/feature develop git rebase --onto master feature develop Note: "master" here means remote upstream repo's master branch. OR git rebasegit rebase git rebase <remote_repo>/<remote_branch> <your_branch_name> git rebase --onto <first_this> <then_this> <last> Syntax for git rebase
  • 22. What if the feature branch needs to rebase against aWhat if the feature branch needs to rebase against a upstream repo's master branch shared by everyone?upstream repo's master branch shared by everyone? Note: "master" here means remote upstream repo's master branch.
  • 23. What if the feature branch needs to rebase against aWhat if the feature branch needs to rebase against a upstream repo's master branch shared by everyone?upstream repo's master branch shared by everyone? Note: "master" here means remote upstream repo's master branch.
  • 25. Rebase Conflicts require manual fixesRebase Conflicts require manual fixes (because git isn't clever enough to fix conflicts) 1. Locate conflict markers (<<<<<<) and make edits to resolve 2. Resolve a conflict in each file with git add <filename> 3. ​git rebase --continue 4. Alternatively, you can undo the git rebase with git rebase --abort
  • 26. Fixing git rebase conflicts is notFixing git rebase conflicts is not always the right solutionalways the right solution git checkout master git branch -D feature git fetch master git checkout -b feature master/feature git checkout -b develop_v2 git merge develop_v1 git branch -D develop_v1 git fetch master git checkout [YOUR BRANCH] git rebase --onto master/feature [commit] OR
  • 27. Different computers, sameDifferent computers, same branchbranch git fetch origin && git rebase origin/<MY_BRANCH> Note: "origin" is your personal cloned copy of an upstream master repo git pull --rebase Or, equivalently
  • 28.
  • 29. git rebase --interactive <HASH> or git rebase --interactive HEAD^ Defn: To re-order, edit, squash, or remove many commits at once
  • 30. git rebase -i HEAD~5
  • 32. git resetgit reset Defn: Reset current HEAD to the specified state
  • 33. git reset --soft HEAD^ Defn: Set files from previous commit onto staging area. HEAD points to the previous commit. This leaves all your changed files as "Changes to be committed".
  • 35. git reset --hard HEAD^ Defn: Abandon everything since your last commit. HEAD points to the previous commit. Nothing is in staging. Use with great caution
  • 36. git refloggit reflog Defn: shows all the commits and actions on your machine that has ever happened such as branch switches, rebases, resets, branch deletions, cherry-picks, reverts.
  • 37. git reflog git reflog --grep="Revert" How to make git reflog more usefulHow to make git reflog more useful git reflog --all --date=iso
  • 38. You can undo a hard reset with the help of git reflogYou can undo a hard reset with the help of git reflog git reset --hard HEAD^^ to remove the last 3 commits
  • 39. You can undo a hard reset with git reflog + git reset --hardYou can undo a hard reset with git reflog + git reset --hard git reset --hard a64b0f2 to restore branch to previous stategit reset --hard a64b0f2 to restore branch to previous state
  • 40. Why use git reflog?Why use git reflog? You lost commits when you did a git reset --hard You squashed too many commits into 1 commit, so you want to undo git rebase -i You accidentally deleted branches and want to restore them Summary: Use reflog to look up old lost commits
  • 41. Use cases for git reflogUse cases for git reflog Look up a commit hash. Then either create a new (un-named) branch out of this commit git checkout -b <COMMIT_HASH> reset your branch to a previous state git reset --hard <COMMIT_HASH> git reset --soft <COMMIT_HASH> cherrypick that lost commit on top of your branch git cherry-pick <COMMIT_HASH>
  • 42. How long does theHow long does the output of reflog last?output of reflog last? Hanging commits are removed from the local repository by garbage collection (gc) or by manual removal. Default is 30 days. [gc] reflogExpire = never reflogExpireUnreachable = never
  • 43. git revert 638351801cd802d6e0c4e601db1eca801dd58936 Defn: Makes a revert commit with a message that states the specified commit is reverted git revert <HASH>
  • 44. Defn: Revert changes specified by 4th last commit away from HEAD and create a new commit with reverted changes. git revert HEAD~3
  • 45. git revert --continue Continue after resolving conflicts git revert --abort Cancel operation and return to pre-sequence state git revert --quit Can be used to start over after a failed cherry-pick or revert Git revert conflictsGit revert conflicts
  • 46. When to use git reset vs. git revertWhen to use git reset vs. git revert
  • 48. Permanent MistakesPermanent Mistakes git push -f origin <REMOTE>
  • 49. SummarySummary If you run into git problems, the solution is most likely to use one of these -- git rebase git reset git reflog git revert
  • 50. III. Automate gitIII. Automate git
  • 51. Problem: Repetitive branch deletingProblem: Repetitive branch deleting vagrant@precise64:~/work/savage$ git push origin :73997184 To git@github.com:onceuponatimeforever/savage.git - [deleted] 73997184 vagrant@precise64:~/work/savage$ git push origin :76321732-on-mast To git@github.com:onceuponatimeforever/savage.git - [deleted] 76321732-on-master vagrant@precise64:~/work/savage$ git push origin :77910316 To git@github.com:onceuponatimeforever/savage.git - [deleted] 77910316 vagrant@precise64:~/work/savage$ git push origin :77910316-bottle To git@github.com:onceuponatimeforever/savage.git - [deleted] 77910316-bottle vagrant@precise64:~/work/savage$ git push origin :77910316-bottle- To git@github.com:onceuponatimeforever/savage.git - [deleted] 77910316-bottle-from-scratch vagrant@precise64:~/work/savage$ git push origin :2.0/master
  • 52. IPython notebook supports gitIPython notebook supports git
  • 53. Solution: IPython notebook scriptSolution: IPython notebook script
  • 54. Problem: Fetch & rebase repetitionsProblem: Fetch & rebase repetitions cd <PROJECT> git fetch upstream git rebase upstream/master cd ../<ANOTHER_PROJECT> git fetch upstream git rebase upstream/master # And again ....
  • 55. Solution: IPython notebook scriptSolution: IPython notebook script list_of_projects = ['ipython', 'oh-mainline'] def update(project): %cd {project} !git checkout master !git fetch upstream !git rebase upstream/master !git push origin master %cd .. print "Done git rebasing this repoo: ", {project} for project in list_of_projects: update(list_of_projects[project]) print "---------------------------------"
  • 56. Solution: IPython notebook scriptSolution: IPython notebook script