SlideShare a Scribd company logo
1 of 10
Download to read offline
Git Tricks
git utilities
that make
life git easier
Git Logo by Jason Long (CC BY 3.0), Image by Steven Depolo (CC BY 2.0)
$ git commit --amend -m "new message"
Change commit message of previous commit
(Careful, don't do this if you already pushed the commit)
$ git add [missing files]
$ git commit --amend #uses the previous commit's message
Forgot to commit files?
$ git reset --soft HEAD@{1}
$ git commit -C HEAD@{1}
Undo the amending
Interactive staging (also allows committing only parts of files)
$ git add -i
$ git add --patch [file]
2
Git Tricks—amend, add --patch
Image by drawmeanidea.com
$ git stash
$ git stash pop
Temporarily store/retrieve all modified tracked files
$ git stash list
List all stashed changesets
What did I work on recently?
Show differences that are not staged yet
$ git diff
Shows differences between staging and the last file version
$ git diff --staged
$ git reflog
Log of all recent actions
3
Git Tricks—reflog, diff, stash
$ git log --abbrev-commit --pretty=oneline
Show changesets in the log
Shorter version of the git log
$ git log -p
Show pretty graph of git history
$ git log --graph --decorate --pretty=oneline --abbrev-commit
$ git rebase [branch]
History is becoming cluttered with merge commits
Git Tricks—log, blame, rebase
$ git blame --date=short [file]
Show what revision and author last modified each line
4
■ Easiest way to integrate the branches is merge
□ Will create merge commits
https://git-scm.com/book/en/v1/Git-Branching-Rebasing (MIT)
$ git checkout master
$ git merge experiment
$ git checkout –b "experiment"
$ git commit –a –m "C3"
5
Rebase—setup
■ Created "experiment" branch
to try something
6
$ git checkout experiment
$ git rebase master
■ Afterwards: fast-forward the master branch
□ No merge commits
$ git checkout master
$ git merge experiment
https://git-scm.com/book/en/v1/Git-Branching-Rebasing (MIT) 6
Rebase—execution
■ git rebase
□ Take all the changes that were committed on
one branch and replay them on another one
□ Please(!) only with local commits
■ Problem: Quickly get changes from other commits
without having to merge entire branches
■ git cherry-pick
□ apply the changes introduced
by existing commits
$ git checkout master
$ git log --abbrev-commit --pretty=oneline
d7ef34a C3: Implement feature
0be778a C4: critical change introduced
C0 C1 C2
CA
C3
CB
C4 C5
C4
critical
change
master
experiment
$ git checkout experiment
$ git cherry-pick 0be778a
7
Git cherry-pick
8
Some Git Self-help Resources
■ How to undo (almost) anything with git – guide by Github
□ https://github.com/blog/2019-how-to-undo-almost-anything-with-git
■ Git cheat sheet – by Github
□ https://training.github.com/kit/downloads/github-git-cheat-sheet.pdf
■ Git pretty – troubleshooting flowchart
□ http://justinhileman.info/article/git-pretty/
■ Git FAQ – answers to common questions
□ http://gitfaq.org/
□ https://git.wiki.kernel.org/index.php/Git_FAQ
■ Many GUIs for git available (https://git-scm.com/downloads/guis)
□ Make some complex git interactions much simpler
□ Draw pretty commit graphs, overviews of branches and merges
□ E.g. GitX, TortoiseGit, SourceTree, Tower, SmartGit, gitg, git-cola
■ Github Integration
□ Github also provides git tools
(https://mac.github.com/, https://windows.github.com/)
■ Git extras (https://github.com/tj/git-extras)
□ Common git commands bundled
9
Some Tooling Suggestions
1
Conclusion
Who did what, when, and why?
Git (and version control in general) helps answer the question
P.S. Try to avoid push --force. Seriously.
knowing some git tricks helps you get there faster.

More Related Content

What's hot

Git Workflow With Gitflow
Git Workflow With GitflowGit Workflow With Gitflow
Git Workflow With Gitflow
Josh Dvir
 
Open Source Collaboration With Git And Git Hub
Open Source Collaboration With Git And Git HubOpen Source Collaboration With Git And Git Hub
Open Source Collaboration With Git And Git Hub
Nick Quaranto
 

What's hot (20)

Git basics for beginners
Git basics for beginnersGit basics for beginners
Git basics for beginners
 
Git and git workflow best practice
Git and git workflow best practiceGit and git workflow best practice
Git and git workflow best practice
 
Git tutorial
Git tutorialGit tutorial
Git tutorial
 
Git Series. Episode 2. Merge, Upstream Commands and Tags
Git Series. Episode 2. Merge, Upstream Commands and TagsGit Series. Episode 2. Merge, Upstream Commands and Tags
Git Series. Episode 2. Merge, Upstream Commands and Tags
 
Git with the flow
Git with the flowGit with the flow
Git with the flow
 
Git & Github
Git & GithubGit & Github
Git & Github
 
Git Workflow With Gitflow
Git Workflow With GitflowGit Workflow With Gitflow
Git Workflow With Gitflow
 
Git 101
Git 101Git 101
Git 101
 
Git Version Control System
Git Version Control SystemGit Version Control System
Git Version Control System
 
Open Source Collaboration With Git And Git Hub
Open Source Collaboration With Git And Git HubOpen Source Collaboration With Git And Git Hub
Open Source Collaboration With Git And Git Hub
 
Git in 10 minutes
Git in 10 minutesGit in 10 minutes
Git in 10 minutes
 
Git flow Introduction
Git flow IntroductionGit flow Introduction
Git flow Introduction
 
Version Control & Git
Version Control & GitVersion Control & Git
Version Control & Git
 
Advanced Git
Advanced GitAdvanced Git
Advanced Git
 
Brief tutorial on Git
Brief tutorial on GitBrief tutorial on Git
Brief tutorial on Git
 
Intro to git and git hub
Intro to git and git hubIntro to git and git hub
Intro to git and git hub
 
Git and git hub
Git and git hubGit and git hub
Git and git hub
 
Git flow
Git flowGit flow
Git flow
 
Git commands
Git commandsGit commands
Git commands
 
沒有 GUI 的 Git
沒有 GUI 的 Git沒有 GUI 的 Git
沒有 GUI 的 Git
 

Similar to Git Tricks — git utilities that make life git easier

Git Distributed Version Control System
Git   Distributed Version Control SystemGit   Distributed Version Control System
Git Distributed Version Control System
Victor Wong
 

Similar to Git Tricks — git utilities that make life git easier (20)

GIT_In_90_Minutes
GIT_In_90_MinutesGIT_In_90_Minutes
GIT_In_90_Minutes
 
Introduction To Git Workshop
Introduction To Git WorkshopIntroduction To Git Workshop
Introduction To Git Workshop
 
Pro git - grasping it conceptually
Pro git - grasping it conceptuallyPro git - grasping it conceptually
Pro git - grasping it conceptually
 
Git github
Git githubGit github
Git github
 
Wokshop de Git
Wokshop de Git Wokshop de Git
Wokshop de Git
 
How to Really Get Git
How to Really Get GitHow to Really Get Git
How to Really Get Git
 
Git
GitGit
Git
 
Learning Basic GIT Cmd
Learning Basic GIT CmdLearning Basic GIT Cmd
Learning Basic GIT Cmd
 
Advanced Git Tutorial
Advanced Git TutorialAdvanced Git Tutorial
Advanced Git Tutorial
 
Mastering git - Workflow
Mastering git - WorkflowMastering git - Workflow
Mastering git - Workflow
 
Get Good With Git
Get Good With GitGet Good With Git
Get Good With Git
 
Gittalk
GittalkGittalk
Gittalk
 
The everyday developer's guide to version control with Git
The everyday developer's guide to version control with GitThe everyday developer's guide to version control with Git
The everyday developer's guide to version control with Git
 
Working with Git
Working with GitWorking with Git
Working with Git
 
Introducción a git y GitHub
Introducción a git y GitHubIntroducción a git y GitHub
Introducción a git y GitHub
 
Git Started With Git
Git Started With GitGit Started With Git
Git Started With Git
 
GIT Basics
GIT BasicsGIT Basics
GIT Basics
 
Git Distributed Version Control System
Git   Distributed Version Control SystemGit   Distributed Version Control System
Git Distributed Version Control System
 
Git workflows automat-it
Git workflows automat-itGit workflows automat-it
Git workflows automat-it
 
Git and github 101
Git and github 101Git and github 101
Git and github 101
 

More from Christoph Matthies

Scrum2Kanban: Integrating Kanban and Scrum in a University Software Engineeri...
Scrum2Kanban: Integrating Kanban and Scrum in a University Software Engineeri...Scrum2Kanban: Integrating Kanban and Scrum in a University Software Engineeri...
Scrum2Kanban: Integrating Kanban and Scrum in a University Software Engineeri...
Christoph Matthies
 

More from Christoph Matthies (20)

Investigating Software Engineering Artifacts in DevOps Through the Lens of Bo...
Investigating Software Engineering Artifacts in DevOps Through the Lens of Bo...Investigating Software Engineering Artifacts in DevOps Through the Lens of Bo...
Investigating Software Engineering Artifacts in DevOps Through the Lens of Bo...
 
Automated Exercises & Software Development Data
Automated Exercises & Software Development DataAutomated Exercises & Software Development Data
Automated Exercises & Software Development Data
 
Challenges (and Opportunities!) of a Remote Agile Software Engineering Projec...
Challenges (and Opportunities!) of a Remote Agile Software Engineering Projec...Challenges (and Opportunities!) of a Remote Agile Software Engineering Projec...
Challenges (and Opportunities!) of a Remote Agile Software Engineering Projec...
 
Experience vs Data: A Case for More Data-informed Retrospective Activities
Experience vs Data: A Case for More Data-informed Retrospective ActivitiesExperience vs Data: A Case for More Data-informed Retrospective Activities
Experience vs Data: A Case for More Data-informed Retrospective Activities
 
More than Code: Contributions in Scrum Software Engineering Teams
More than Code: Contributions in Scrum Software Engineering TeamsMore than Code: Contributions in Scrum Software Engineering Teams
More than Code: Contributions in Scrum Software Engineering Teams
 
Agile Software Development Practices: Perceptions & Project Data
Agile Software Development Practices: Perceptions & Project DataAgile Software Development Practices: Perceptions & Project Data
Agile Software Development Practices: Perceptions & Project Data
 
The Road to Data-Informed Agile Development Processes
The Road to Data-Informed Agile Development ProcessesThe Road to Data-Informed Agile Development Processes
The Road to Data-Informed Agile Development Processes
 
Counteracting Agile Retrospective Problems with Retrospective Activities
Counteracting Agile Retrospective Problems with Retrospective ActivitiesCounteracting Agile Retrospective Problems with Retrospective Activities
Counteracting Agile Retrospective Problems with Retrospective Activities
 
Using Data to Inform Decisions in Agile Software Development
Using Data to Inform Decisions in Agile Software Development Using Data to Inform Decisions in Agile Software Development
Using Data to Inform Decisions in Agile Software Development
 
An Additional Set of (Automated) Eyes: Chatbots for Agile Retrospectives
An Additional Set of (Automated) Eyes: Chatbots for Agile RetrospectivesAn Additional Set of (Automated) Eyes: Chatbots for Agile Retrospectives
An Additional Set of (Automated) Eyes: Chatbots for Agile Retrospectives
 
Feedback in Scrum: Data-Informed Retrospectives
Feedback in Scrum: Data-Informed Retrospectives Feedback in Scrum: Data-Informed Retrospectives
Feedback in Scrum: Data-Informed Retrospectives
 
Beyond Surveys: Analyzing Software Development Artifacts to Assess Teaching E...
Beyond Surveys: Analyzing Software Development Artifacts to Assess Teaching E...Beyond Surveys: Analyzing Software Development Artifacts to Assess Teaching E...
Beyond Surveys: Analyzing Software Development Artifacts to Assess Teaching E...
 
Scrum2Kanban: Integrating Kanban and Scrum in a University Software Engineeri...
Scrum2Kanban: Integrating Kanban and Scrum in a University Software Engineeri...Scrum2Kanban: Integrating Kanban and Scrum in a University Software Engineeri...
Scrum2Kanban: Integrating Kanban and Scrum in a University Software Engineeri...
 
Should I Bug You? Identifying Domain Experts in Software Projects Using Code...
 Should I Bug You? Identifying Domain Experts in Software Projects Using Code... Should I Bug You? Identifying Domain Experts in Software Projects Using Code...
Should I Bug You? Identifying Domain Experts in Software Projects Using Code...
 
Introduction to Lean Software & Kanban
Introduction to Lean Software & KanbanIntroduction to Lean Software & Kanban
Introduction to Lean Software & Kanban
 
Lightweight Collection and Storage of Software Repository Data with DataRover
Lightweight Collection and Storage of  Software Repository Data with DataRoverLightweight Collection and Storage of  Software Repository Data with DataRover
Lightweight Collection and Storage of Software Repository Data with DataRover
 
Pybelsberg — Constraint-based Programming in Python
Pybelsberg — Constraint-based Programming in PythonPybelsberg — Constraint-based Programming in Python
Pybelsberg — Constraint-based Programming in Python
 
How to reverse engineer Android applications—using a popular word game as an ...
How to reverse engineer Android applications—using a popular word game as an ...How to reverse engineer Android applications—using a popular word game as an ...
How to reverse engineer Android applications—using a popular word game as an ...
 
Beat Your Mom At Solitaire—Reverse Engineering of Computer Games
Beat Your Mom At Solitaire—Reverse Engineering of Computer GamesBeat Your Mom At Solitaire—Reverse Engineering of Computer Games
Beat Your Mom At Solitaire—Reverse Engineering of Computer Games
 
Introduction to Homomorphic Encryption
Introduction to Homomorphic EncryptionIntroduction to Homomorphic Encryption
Introduction to Homomorphic Encryption
 

Recently uploaded

Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 

Recently uploaded (20)

ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 

Git Tricks — git utilities that make life git easier

  • 1. Git Tricks git utilities that make life git easier Git Logo by Jason Long (CC BY 3.0), Image by Steven Depolo (CC BY 2.0)
  • 2. $ git commit --amend -m "new message" Change commit message of previous commit (Careful, don't do this if you already pushed the commit) $ git add [missing files] $ git commit --amend #uses the previous commit's message Forgot to commit files? $ git reset --soft HEAD@{1} $ git commit -C HEAD@{1} Undo the amending Interactive staging (also allows committing only parts of files) $ git add -i $ git add --patch [file] 2 Git Tricks—amend, add --patch Image by drawmeanidea.com
  • 3. $ git stash $ git stash pop Temporarily store/retrieve all modified tracked files $ git stash list List all stashed changesets What did I work on recently? Show differences that are not staged yet $ git diff Shows differences between staging and the last file version $ git diff --staged $ git reflog Log of all recent actions 3 Git Tricks—reflog, diff, stash
  • 4. $ git log --abbrev-commit --pretty=oneline Show changesets in the log Shorter version of the git log $ git log -p Show pretty graph of git history $ git log --graph --decorate --pretty=oneline --abbrev-commit $ git rebase [branch] History is becoming cluttered with merge commits Git Tricks—log, blame, rebase $ git blame --date=short [file] Show what revision and author last modified each line 4
  • 5. ■ Easiest way to integrate the branches is merge □ Will create merge commits https://git-scm.com/book/en/v1/Git-Branching-Rebasing (MIT) $ git checkout master $ git merge experiment $ git checkout –b "experiment" $ git commit –a –m "C3" 5 Rebase—setup ■ Created "experiment" branch to try something
  • 6. 6 $ git checkout experiment $ git rebase master ■ Afterwards: fast-forward the master branch □ No merge commits $ git checkout master $ git merge experiment https://git-scm.com/book/en/v1/Git-Branching-Rebasing (MIT) 6 Rebase—execution ■ git rebase □ Take all the changes that were committed on one branch and replay them on another one □ Please(!) only with local commits
  • 7. ■ Problem: Quickly get changes from other commits without having to merge entire branches ■ git cherry-pick □ apply the changes introduced by existing commits $ git checkout master $ git log --abbrev-commit --pretty=oneline d7ef34a C3: Implement feature 0be778a C4: critical change introduced C0 C1 C2 CA C3 CB C4 C5 C4 critical change master experiment $ git checkout experiment $ git cherry-pick 0be778a 7 Git cherry-pick
  • 8. 8 Some Git Self-help Resources ■ How to undo (almost) anything with git – guide by Github □ https://github.com/blog/2019-how-to-undo-almost-anything-with-git ■ Git cheat sheet – by Github □ https://training.github.com/kit/downloads/github-git-cheat-sheet.pdf ■ Git pretty – troubleshooting flowchart □ http://justinhileman.info/article/git-pretty/ ■ Git FAQ – answers to common questions □ http://gitfaq.org/ □ https://git.wiki.kernel.org/index.php/Git_FAQ
  • 9. ■ Many GUIs for git available (https://git-scm.com/downloads/guis) □ Make some complex git interactions much simpler □ Draw pretty commit graphs, overviews of branches and merges □ E.g. GitX, TortoiseGit, SourceTree, Tower, SmartGit, gitg, git-cola ■ Github Integration □ Github also provides git tools (https://mac.github.com/, https://windows.github.com/) ■ Git extras (https://github.com/tj/git-extras) □ Common git commands bundled 9 Some Tooling Suggestions
  • 10. 1 Conclusion Who did what, when, and why? Git (and version control in general) helps answer the question P.S. Try to avoid push --force. Seriously. knowing some git tricks helps you get there faster.