SlideShare a Scribd company logo
1 of 57
Download to read offline
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.

More Related Content

What's hot (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 to 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 to 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
 

More from 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
 

More from 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
 

Recently uploaded

Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 

Recently uploaded (20)

Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 

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