際際滷

際際滷Share a Scribd company logo
Git course
Level 2
Terje Sandstr淡m, Inmeta Consulting, 2014
Terje Sandstr淡m, Inmeta Consulting, 2014
Prepare: Do you have .
 Do you have Git installed
 From cmd line: git version
 From VS, Git settings, Install 3rd party 
 Or Http://git-scm.com/download/win
 Sourcetree installed Http://www.sourcetreeapp.com/download
 Do you have PoshGit installed :
 From https://windows.github.com/ (You get 2 apps, one of them is PoshGit)
 Or https://chocolatey.org/packages/poshgit (you might need
https://chocolatey.org/ first)
 > cinst poshgit
Terje Sandstr淡m, Inmeta Consulting, 2014
VS Title changer
 Download: http://visualstudiogallery.msdn.microsoft.com/2e8ebfe4-
023f-4c4d-9b7a-d05bbc5cb239
 Script from here:
 https://gist.github.com/OsirisTerje/ed23ec78720c7517ec5e
 All info is available from starting here:
 https://gist.github.com/OsirisTerje
Terje Sandstr淡m, Inmeta Consulting, 2014
You are a master of
 Clone
 Commit
 Pull
 Fetch
 Push
 Branch
 Merge
 Remote
Terje Sandstr淡m, Inmeta Consulting, 2014
Setup
 Use the remote at Labcollection
 http://tfs.osiris.no:8080/tfs/LabCollection/_git/Git-CourseWorkshop2014
 Open your named repository or create a new one including your name
 Set .gitignore
 Open the solution from last session
 Or
 Create a new solution at the same place,
 C# class library, add a single class
 push it to the remote
Terje Sandstr淡m, Inmeta Consulting, 2014
Commit amend
 Do a change
 Commit (DONT PUSH IT)
 Do another change
Terje Sandstr淡m, Inmeta Consulting, 2014
Commit --amend
 Amend a commit
 Sequentially add commits together to form a single commit
 Change the last commit
 Content
 Commit comment
 Git commit amend mNew msg
ONLY before push
Terje Sandstr淡m, Inmeta Consulting, 2014
Delete branches
 Locally:
 Git branch d/-D Whatever
 Remote:
 Git push origin delete Whatever
Terje Sandstr淡m, Inmeta Consulting, 2014
Terje Sandstr淡m, Inmeta Consulting, 2014
I have modified files and want to undo
 Existing class, add a comment (Dont commit)
 See VS marking
 > Git status
Terje Sandstr淡m, Inmeta Consulting, 2014
Undo last modified files
 Visual Studio: Undo
 Git command line
 >Git reset --hard
 Undoes all changes
 >Git reset hard filename
 Undoes the particular file
Terje Sandstr淡m, Inmeta Consulting, 2014
Getting things back to start
 Do a change to the class
 >Git checkout .
 Now the change is removed.
 Do another change, stage the change
 >Git checkout .
 Nothing seems to change, right ?
 Git checkout affects the working tree! Not the index!
Terje Sandstr淡m, Inmeta Consulting, 2014
How to undo
 If staged
 Git reset hard // cleans both index and working tree
 If not staged
 Git checkout . // cleans working tree
Terje Sandstr淡m, Inmeta Consulting, 2014
Visual Studio hickup:
 Change 1:
 Add a new class (Dont commit)
 Create a new branch
 Notice: You can easily switch to the new branch and back and forth to
master
 Change 2:
 Do a change in existing class1
 Switch branch: You may get

Terje Sandstr淡m, Inmeta Consulting, 2014
How to fix a mess like this:
 Change 2:
a) >git reset hard
a) I loose the changes to exiting class, but the the new class exist
a) After this reset, we can switch branch and commit the new class.
b) If I Want to keep the first change, I must commit that file alone in master
a) This file is not tracked
b) > git add filename
c) > git commit
Notice: Commit on cmd line only commits what is in the index, Commit in VS
stages AND commits.
Terje Sandstr淡m, Inmeta Consulting, 2014
How to remove the added class
 We now have only untracked files left
 VS may show it as Included, and nothing in Untracked, but git status will
show the truth
 >git clean f
 This will remove the last file
Terje Sandstr淡m, Inmeta Consulting, 2014
Setting up a more usable editor
 Download Notedpad++
 http://notepad-plus-plus.org/download/v6.6.2.html
 Edit .gitconfig at c:users(yourusername)
[core]
autocrlf = true
editor = 'C:/Program Files (x86)/Notepad++/notepad++.exe'
Terje Sandstr淡m, Inmeta Consulting, 2014
Changing after push
 You must revert the change
 Do a change to your file
 Commit (you may or may not push)
 Think hard, and regret what you did .
 >Git revert HEAD
Terje Sandstr淡m, Inmeta Consulting, 2014
Reset versus Revert
A B -B = ARevert
A B = AReset
Terje Sandstr淡m, Inmeta Consulting, 2014
I have committed and now I regret that
 Experiment:
 Change a method, and commit the change
Terje Sandstr淡m, Inmeta Consulting, 2014
I have committed and now I regret that
solutions
1. I want to trash it, that code was awful!
1. >git reset hard HEAD~1
2. I wasnt finished, I want to add more to the same commit, but keep
the changes, just undo my commit.
1. >git reset HEAD~1 (aka git reset mixed )
3. Same as 2, but I will keep it staged, just going to add some more
files
1. >git reset soft HEAD~1
Terje Sandstr淡m, Inmeta Consulting, 2014
Git tree movements visualized
History
Stage/Index
Working directory
Git reset hard ..
Git reset (--mixed) ..
Git reset --soft ..
Git add 
Git commit
Git checkout
Terje Sandstr淡m, Inmeta Consulting, 2014
Setting up the merge tool for command
line
 Add section to global .gitconfig
 Download from
https://gist.github.com/OsirisTerje/42a913d2920723bc777a
 (May need to add paths)
Terje Sandstr淡m, Inmeta Consulting, 2014
Fast forwarding merges
 Experiment:
 Ensure origin/master is aligned with master (do a push)
 Create a new branch Dev88
 Change the DoSomething method
 The branch tree is now linear, Dev88 is just ahead of master
 We can now forward merge master to Dev88
Terje Sandstr淡m, Inmeta Consulting, 2014
FF
1. Using rebase
1. Select master branch
2. >git rebase Dev88
2. Using merge
1. Select master branch
2. >git Merge Dev88
Terje Sandstr淡m, Inmeta Consulting, 2014
Cleaning up merge commits
 Work:
 Create and Checkout Branch Test
 Change Class1
 Switch back to Master
 Change class1 somewhere else
 Merge in branch Test
 Watch the Sourcetree log.
Terje Sandstr淡m, Inmeta Consulting, 2014
How to clean up the merges
 > Git rebase origin/master
 If conflict:
 Dont edit the shown mergefile with a lot of >>>>>>>> markers in
 This is NOT your source file !!!!
 > Git mergetool
Terje Sandstr淡m, Inmeta Consulting, 2014
 Git rebase continue
 Remove trash
 Consider adding .orig to gitignore
Terje Sandstr淡m, Inmeta Consulting, 2014
The result
The merge commit has been eliminated!
But Beware:
History has been rewritten !
(Dont do rebasing if you have pushed your commits! But not an issue in this case since we rebase to origin/master)
Terje Sandstr淡m, Inmeta Consulting, 2014
Working in master or branch
 Preferably work in a dev branch
 Commit often
 Merge often
 Consider doing a rebase origin to get rid of the merge commits
 Pull to master, merge over to the dev branch
 Alternative: pull rebase !
Terje Sandstr淡m, Inmeta Consulting, 2014
Experiment with multiple developers
 Join up 2 persons, on same repo
 Dev1:
 Do a change, commit and push
 Dev2:
 Do own change. Sees this in SourceTree
Terje Sandstr淡m, Inmeta Consulting, 2014
Dev 2 decide on a pull rebase
 >git pull rebase
 Patch may or may not fail, assume it fails:
 >Git mergetool
 Starts the VS merge, resolve the merge
Terje Sandstr淡m, Inmeta Consulting, 2014
Sourcetree before/after merge (rebase)
Terje Sandstr淡m, Inmeta Consulting, 2014
Merge branches using rebasing
 I dont want the merge commits
 Alt.1:
 Merge the standard way
 Use rebase origin/{branch} to get rid of the merge commits
 Alt.2:
 Merge using rebasing instead
 Rebase : Add changes on top of latest target branch changes.
Terje Sandstr淡m, Inmeta Consulting, 2014
Experiment: Rebase merging
 Create a branch off master, call it devX
 Switch to it
 Add a new class here
 Switch to master
 Change something here
 Forward merge master
Terje Sandstr淡m, Inmeta Consulting, 2014
Rebase devX on top of master
 Git checkout dev2 // The branch which will be rebased on top of the next one
 Git rebase master // the branch we will rebase onto
Forward merge master after this:
 Go to the "oldest" branch, merge the "newest" branch into the oldest
 That way the oldest is moved forward to the newest.
 Git checkout master, git rebase dev3
Terje Sandstr淡m, Inmeta Consulting, 2014
Squashing  combining commits
 Experiment:
 Create a new branch , Ny10
 Make a change, commit
 Make another change, commit
 Checkout master
 >git merge squash Ny10
 >git commit mSquashed
Terje Sandstr淡m, Inmeta Consulting, 2014
Ad

Recommended

Techoalien git
Techoalien git
Aditya Tiwari
[TestWarez 2017] Behavior Driven Development in a complex environment - Consu...
[TestWarez 2017] Behavior Driven Development in a complex environment - Consu...
Stowarzyszenie Jakoci System坦w Informatycznych (SJSI)
Git talk from Open 2011 conference in Israel
Git talk from Open 2011 conference in Israel
Reuven Lerner
Git get-the-job-done
Git get-the-job-done
Daniel Kummer
Code reviews vs Pull requests
Code reviews vs Pull requests
Tim Pettersen
Git Anti-Patterns - Extended Version With 28 Common Anti-Patterns) - SCTurkey...
Git Anti-Patterns - Extended Version With 28 Common Anti-Patterns) - SCTurkey...
Lemi Orhan Ergin
Git Anti-Patterns: How To Mess Up With Git and Love it Again - DevoxxPL 2017
Git Anti-Patterns: How To Mess Up With Git and Love it Again - DevoxxPL 2017
Lemi Orhan Ergin
Techoalien git
Techoalien git
Aditya Tiwari
Techoalien git
Techoalien git
Aditya Tiwari
Git Anti Patterns - XP Days Ukraine 2017
Git Anti Patterns - XP Days Ukraine 2017
Lemi Orhan Ergin
Git: Overview, Pitfalls, Best Practices
Git: Overview, Pitfalls, Best Practices
Jeremy Leisy
Git with the flow
Git with the flow
Dana White
MakingGitWorkForYou
MakingGitWorkForYou
Kwen Peterson
Git in 10 minutes
Git in 10 minutes
Safique Ahmed Faruque
Mastering GIT
Mastering GIT
Hasnaeen Rahman
Git session Dropsolid.com
Git session Dropsolid.com
dropsolid
Git-ing out of your git messes
Git-ing out of your git messes
Katie Sylor-Miller
Git tutorial
Git tutorial
mobaires
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 Again
Lemi Orhan Ergin
Git of every day
Git of every day
Alan Descoins
Advanced Git - Functionality and Features
Advanced Git - Functionality and Features
All Things Open
Git
Git
Parag Gupta
Git Merge, Resets and Branches
Git Merge, Resets and Branches
Victor Pudelski
Introduction into Git
Introduction into Git
Serhii Kartashov
Git One Day Training Notes
Git One Day Training Notes
glen_a_smith
An introduction to Git and GitFlow
An introduction to Git and GitFlow
Mark Everard
git fail --force (make it up with your pull requests)
git fail --force (make it up with your pull requests)
Carlos Duarte do Nascimento
Mastering git - Workflow
Mastering git - Workflow
Tahsin Abrar
Making significant Software Architecture decisions
Making significant Software Architecture decisions
Bert Jan Schrijver
Enable Your Cloud Journey With Microsoft Trusted Partner | IFI Tech
Enable Your Cloud Journey With Microsoft Trusted Partner | IFI Tech
IFI Techsolutions

More Related Content

Similar to Git course level 2 (20)

Techoalien git
Techoalien git
Aditya Tiwari
Git Anti Patterns - XP Days Ukraine 2017
Git Anti Patterns - XP Days Ukraine 2017
Lemi Orhan Ergin
Git: Overview, Pitfalls, Best Practices
Git: Overview, Pitfalls, Best Practices
Jeremy Leisy
Git with the flow
Git with the flow
Dana White
MakingGitWorkForYou
MakingGitWorkForYou
Kwen Peterson
Git in 10 minutes
Git in 10 minutes
Safique Ahmed Faruque
Mastering GIT
Mastering GIT
Hasnaeen Rahman
Git session Dropsolid.com
Git session Dropsolid.com
dropsolid
Git-ing out of your git messes
Git-ing out of your git messes
Katie Sylor-Miller
Git tutorial
Git tutorial
mobaires
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 Again
Lemi Orhan Ergin
Git of every day
Git of every day
Alan Descoins
Advanced Git - Functionality and Features
Advanced Git - Functionality and Features
All Things Open
Git
Git
Parag Gupta
Git Merge, Resets and Branches
Git Merge, Resets and Branches
Victor Pudelski
Introduction into Git
Introduction into Git
Serhii Kartashov
Git One Day Training Notes
Git One Day Training Notes
glen_a_smith
An introduction to Git and GitFlow
An introduction to Git and GitFlow
Mark Everard
git fail --force (make it up with your pull requests)
git fail --force (make it up with your pull requests)
Carlos Duarte do Nascimento
Mastering git - Workflow
Mastering git - Workflow
Tahsin Abrar
Git Anti Patterns - XP Days Ukraine 2017
Git Anti Patterns - XP Days Ukraine 2017
Lemi Orhan Ergin
Git: Overview, Pitfalls, Best Practices
Git: Overview, Pitfalls, Best Practices
Jeremy Leisy
Git with the flow
Git with the flow
Dana White
MakingGitWorkForYou
MakingGitWorkForYou
Kwen Peterson
Git session Dropsolid.com
Git session Dropsolid.com
dropsolid
Git-ing out of your git messes
Git-ing out of your git messes
Katie Sylor-Miller
Git tutorial
Git tutorial
mobaires
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 Again
Lemi Orhan Ergin
Advanced Git - Functionality and Features
Advanced Git - Functionality and Features
All Things Open
Git Merge, Resets and Branches
Git Merge, Resets and Branches
Victor Pudelski
Git One Day Training Notes
Git One Day Training Notes
glen_a_smith
An introduction to Git and GitFlow
An introduction to Git and GitFlow
Mark Everard
git fail --force (make it up with your pull requests)
git fail --force (make it up with your pull requests)
Carlos Duarte do Nascimento
Mastering git - Workflow
Mastering git - Workflow
Tahsin Abrar

Recently uploaded (20)

Making significant Software Architecture decisions
Making significant Software Architecture decisions
Bert Jan Schrijver
Enable Your Cloud Journey With Microsoft Trusted Partner | IFI Tech
Enable Your Cloud Journey With Microsoft Trusted Partner | IFI Tech
IFI Techsolutions
UPDASP a project coordination unit ......
UPDASP a project coordination unit ......
withrj1
What is data visualization and how data visualization tool can help.pdf
What is data visualization and how data visualization tool can help.pdf
Varsha Nayak
Who will create the languages of the future?
Who will create the languages of the future?
Jordi Cabot
Zonerankers Digital marketing solutions
Zonerankers Digital marketing solutions
reenashriee
Download Adobe Illustrator Crack free for Windows 2025?
Download Adobe Illustrator Crack free for Windows 2025?
grete1122g
Application Modernization with Choreo - The AI-Native Internal Developer Plat...
Application Modernization with Choreo - The AI-Native Internal Developer Plat...
WSO2
How the US Navy Approaches DevSecOps with Raise 2.0
How the US Navy Approaches DevSecOps with Raise 2.0
Anchore
How to Choose the Right Web Development Agency.pdf
How to Choose the Right Web Development Agency.pdf
Creative Fosters
Automated Migration of ESRI Geodatabases Using XML Control Files and FME
Automated Migration of ESRI Geodatabases Using XML Control Files and FME
Safe Software
Software Testing & its types (DevOps)
Software Testing & its types (DevOps)
S Pranav (Deepu)
Open Source Software Development Methods
Open Source Software Development Methods
VICTOR MAESTRE RAMIREZ
wAIred_RabobankIgniteSession_12062025.pptx
wAIred_RabobankIgniteSession_12062025.pptx
SimonedeGijt
Advanced Token Development - Decentralized Innovation
Advanced Token Development - Decentralized Innovation
arohisinghas720
SAP PM Module Level-IV Training Complete.ppt
SAP PM Module Level-IV Training Complete.ppt
MuhammadShaheryar36
Step by step guide to install Flutter and Dart
Step by step guide to install Flutter and Dart
S Pranav (Deepu)
SAP Datasphere Catalog L2 (2024-02-07).pptx
SAP Datasphere Catalog L2 (2024-02-07).pptx
HimanshuSachdeva46
Shell Skill Tree - LabEx Certification (LabEx)
Shell Skill Tree - LabEx Certification (LabEx)
VICTOR MAESTRE RAMIREZ
Rierino Commerce Platform - CMS Solution
Rierino Commerce Platform - CMS Solution
Rierino
Making significant Software Architecture decisions
Making significant Software Architecture decisions
Bert Jan Schrijver
Enable Your Cloud Journey With Microsoft Trusted Partner | IFI Tech
Enable Your Cloud Journey With Microsoft Trusted Partner | IFI Tech
IFI Techsolutions
UPDASP a project coordination unit ......
UPDASP a project coordination unit ......
withrj1
What is data visualization and how data visualization tool can help.pdf
What is data visualization and how data visualization tool can help.pdf
Varsha Nayak
Who will create the languages of the future?
Who will create the languages of the future?
Jordi Cabot
Zonerankers Digital marketing solutions
Zonerankers Digital marketing solutions
reenashriee
Download Adobe Illustrator Crack free for Windows 2025?
Download Adobe Illustrator Crack free for Windows 2025?
grete1122g
Application Modernization with Choreo - The AI-Native Internal Developer Plat...
Application Modernization with Choreo - The AI-Native Internal Developer Plat...
WSO2
How the US Navy Approaches DevSecOps with Raise 2.0
How the US Navy Approaches DevSecOps with Raise 2.0
Anchore
How to Choose the Right Web Development Agency.pdf
How to Choose the Right Web Development Agency.pdf
Creative Fosters
Automated Migration of ESRI Geodatabases Using XML Control Files and FME
Automated Migration of ESRI Geodatabases Using XML Control Files and FME
Safe Software
Software Testing & its types (DevOps)
Software Testing & its types (DevOps)
S Pranav (Deepu)
Open Source Software Development Methods
Open Source Software Development Methods
VICTOR MAESTRE RAMIREZ
wAIred_RabobankIgniteSession_12062025.pptx
wAIred_RabobankIgniteSession_12062025.pptx
SimonedeGijt
Advanced Token Development - Decentralized Innovation
Advanced Token Development - Decentralized Innovation
arohisinghas720
SAP PM Module Level-IV Training Complete.ppt
SAP PM Module Level-IV Training Complete.ppt
MuhammadShaheryar36
Step by step guide to install Flutter and Dart
Step by step guide to install Flutter and Dart
S Pranav (Deepu)
SAP Datasphere Catalog L2 (2024-02-07).pptx
SAP Datasphere Catalog L2 (2024-02-07).pptx
HimanshuSachdeva46
Shell Skill Tree - LabEx Certification (LabEx)
Shell Skill Tree - LabEx Certification (LabEx)
VICTOR MAESTRE RAMIREZ
Rierino Commerce Platform - CMS Solution
Rierino Commerce Platform - CMS Solution
Rierino
Ad

Git course level 2

  • 1. Git course Level 2 Terje Sandstr淡m, Inmeta Consulting, 2014 Terje Sandstr淡m, Inmeta Consulting, 2014
  • 2. Prepare: Do you have . Do you have Git installed From cmd line: git version From VS, Git settings, Install 3rd party Or Http://git-scm.com/download/win Sourcetree installed Http://www.sourcetreeapp.com/download Do you have PoshGit installed : From https://windows.github.com/ (You get 2 apps, one of them is PoshGit) Or https://chocolatey.org/packages/poshgit (you might need https://chocolatey.org/ first) > cinst poshgit Terje Sandstr淡m, Inmeta Consulting, 2014
  • 3. VS Title changer Download: http://visualstudiogallery.msdn.microsoft.com/2e8ebfe4- 023f-4c4d-9b7a-d05bbc5cb239 Script from here: https://gist.github.com/OsirisTerje/ed23ec78720c7517ec5e All info is available from starting here: https://gist.github.com/OsirisTerje Terje Sandstr淡m, Inmeta Consulting, 2014
  • 4. You are a master of Clone Commit Pull Fetch Push Branch Merge Remote Terje Sandstr淡m, Inmeta Consulting, 2014
  • 5. Setup Use the remote at Labcollection http://tfs.osiris.no:8080/tfs/LabCollection/_git/Git-CourseWorkshop2014 Open your named repository or create a new one including your name Set .gitignore Open the solution from last session Or Create a new solution at the same place, C# class library, add a single class push it to the remote Terje Sandstr淡m, Inmeta Consulting, 2014
  • 6. Commit amend Do a change Commit (DONT PUSH IT) Do another change Terje Sandstr淡m, Inmeta Consulting, 2014
  • 7. Commit --amend Amend a commit Sequentially add commits together to form a single commit Change the last commit Content Commit comment Git commit amend mNew msg ONLY before push Terje Sandstr淡m, Inmeta Consulting, 2014
  • 8. Delete branches Locally: Git branch d/-D Whatever Remote: Git push origin delete Whatever Terje Sandstr淡m, Inmeta Consulting, 2014
  • 9. Terje Sandstr淡m, Inmeta Consulting, 2014
  • 10. I have modified files and want to undo Existing class, add a comment (Dont commit) See VS marking > Git status Terje Sandstr淡m, Inmeta Consulting, 2014
  • 11. Undo last modified files Visual Studio: Undo Git command line >Git reset --hard Undoes all changes >Git reset hard filename Undoes the particular file Terje Sandstr淡m, Inmeta Consulting, 2014
  • 12. Getting things back to start Do a change to the class >Git checkout . Now the change is removed. Do another change, stage the change >Git checkout . Nothing seems to change, right ? Git checkout affects the working tree! Not the index! Terje Sandstr淡m, Inmeta Consulting, 2014
  • 13. How to undo If staged Git reset hard // cleans both index and working tree If not staged Git checkout . // cleans working tree Terje Sandstr淡m, Inmeta Consulting, 2014
  • 14. Visual Studio hickup: Change 1: Add a new class (Dont commit) Create a new branch Notice: You can easily switch to the new branch and back and forth to master Change 2: Do a change in existing class1 Switch branch: You may get Terje Sandstr淡m, Inmeta Consulting, 2014
  • 15. How to fix a mess like this: Change 2: a) >git reset hard a) I loose the changes to exiting class, but the the new class exist a) After this reset, we can switch branch and commit the new class. b) If I Want to keep the first change, I must commit that file alone in master a) This file is not tracked b) > git add filename c) > git commit Notice: Commit on cmd line only commits what is in the index, Commit in VS stages AND commits. Terje Sandstr淡m, Inmeta Consulting, 2014
  • 16. How to remove the added class We now have only untracked files left VS may show it as Included, and nothing in Untracked, but git status will show the truth >git clean f This will remove the last file Terje Sandstr淡m, Inmeta Consulting, 2014
  • 17. Setting up a more usable editor Download Notedpad++ http://notepad-plus-plus.org/download/v6.6.2.html Edit .gitconfig at c:users(yourusername) [core] autocrlf = true editor = 'C:/Program Files (x86)/Notepad++/notepad++.exe' Terje Sandstr淡m, Inmeta Consulting, 2014
  • 18. Changing after push You must revert the change Do a change to your file Commit (you may or may not push) Think hard, and regret what you did . >Git revert HEAD Terje Sandstr淡m, Inmeta Consulting, 2014
  • 19. Reset versus Revert A B -B = ARevert A B = AReset Terje Sandstr淡m, Inmeta Consulting, 2014
  • 20. I have committed and now I regret that Experiment: Change a method, and commit the change Terje Sandstr淡m, Inmeta Consulting, 2014
  • 21. I have committed and now I regret that solutions 1. I want to trash it, that code was awful! 1. >git reset hard HEAD~1 2. I wasnt finished, I want to add more to the same commit, but keep the changes, just undo my commit. 1. >git reset HEAD~1 (aka git reset mixed ) 3. Same as 2, but I will keep it staged, just going to add some more files 1. >git reset soft HEAD~1 Terje Sandstr淡m, Inmeta Consulting, 2014
  • 22. Git tree movements visualized History Stage/Index Working directory Git reset hard .. Git reset (--mixed) .. Git reset --soft .. Git add Git commit Git checkout Terje Sandstr淡m, Inmeta Consulting, 2014
  • 23. Setting up the merge tool for command line Add section to global .gitconfig Download from https://gist.github.com/OsirisTerje/42a913d2920723bc777a (May need to add paths) Terje Sandstr淡m, Inmeta Consulting, 2014
  • 24. Fast forwarding merges Experiment: Ensure origin/master is aligned with master (do a push) Create a new branch Dev88 Change the DoSomething method The branch tree is now linear, Dev88 is just ahead of master We can now forward merge master to Dev88 Terje Sandstr淡m, Inmeta Consulting, 2014
  • 25. FF 1. Using rebase 1. Select master branch 2. >git rebase Dev88 2. Using merge 1. Select master branch 2. >git Merge Dev88 Terje Sandstr淡m, Inmeta Consulting, 2014
  • 26. Cleaning up merge commits Work: Create and Checkout Branch Test Change Class1 Switch back to Master Change class1 somewhere else Merge in branch Test Watch the Sourcetree log. Terje Sandstr淡m, Inmeta Consulting, 2014
  • 27. How to clean up the merges > Git rebase origin/master If conflict: Dont edit the shown mergefile with a lot of >>>>>>>> markers in This is NOT your source file !!!! > Git mergetool Terje Sandstr淡m, Inmeta Consulting, 2014
  • 28. Git rebase continue Remove trash Consider adding .orig to gitignore Terje Sandstr淡m, Inmeta Consulting, 2014
  • 29. The result The merge commit has been eliminated! But Beware: History has been rewritten ! (Dont do rebasing if you have pushed your commits! But not an issue in this case since we rebase to origin/master) Terje Sandstr淡m, Inmeta Consulting, 2014
  • 30. Working in master or branch Preferably work in a dev branch Commit often Merge often Consider doing a rebase origin to get rid of the merge commits Pull to master, merge over to the dev branch Alternative: pull rebase ! Terje Sandstr淡m, Inmeta Consulting, 2014
  • 31. Experiment with multiple developers Join up 2 persons, on same repo Dev1: Do a change, commit and push Dev2: Do own change. Sees this in SourceTree Terje Sandstr淡m, Inmeta Consulting, 2014
  • 32. Dev 2 decide on a pull rebase >git pull rebase Patch may or may not fail, assume it fails: >Git mergetool Starts the VS merge, resolve the merge Terje Sandstr淡m, Inmeta Consulting, 2014
  • 33. Sourcetree before/after merge (rebase) Terje Sandstr淡m, Inmeta Consulting, 2014
  • 34. Merge branches using rebasing I dont want the merge commits Alt.1: Merge the standard way Use rebase origin/{branch} to get rid of the merge commits Alt.2: Merge using rebasing instead Rebase : Add changes on top of latest target branch changes. Terje Sandstr淡m, Inmeta Consulting, 2014
  • 35. Experiment: Rebase merging Create a branch off master, call it devX Switch to it Add a new class here Switch to master Change something here Forward merge master Terje Sandstr淡m, Inmeta Consulting, 2014
  • 36. Rebase devX on top of master Git checkout dev2 // The branch which will be rebased on top of the next one Git rebase master // the branch we will rebase onto Forward merge master after this: Go to the "oldest" branch, merge the "newest" branch into the oldest That way the oldest is moved forward to the newest. Git checkout master, git rebase dev3 Terje Sandstr淡m, Inmeta Consulting, 2014
  • 37. Squashing combining commits Experiment: Create a new branch , Ny10 Make a change, commit Make another change, commit Checkout master >git merge squash Ny10 >git commit mSquashed Terje Sandstr淡m, Inmeta Consulting, 2014