SlideShare a Scribd company logo
1 of 37
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 (DON’T 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 –m”New 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 (Don’t 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 (Don’t 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 wasn’t 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:
• Don’t 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 !
(Don’t 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 don’t 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 –m”Squashed…”
Terje Sandstrøm, Inmeta Consulting, 2014

More Related Content

Similar to Git course level 2

Beginner's Guide to Version Control with Git
Beginner's Guide to Version Control with GitBeginner's Guide to Version Control with Git
Beginner's Guide to Version Control with GitRobert Lee-Cann
 
Let's Git this Party Started: An Introduction to Git and GitHub
Let's Git this Party Started: An Introduction to Git and GitHubLet's Git this Party Started: An Introduction to Git and GitHub
Let's Git this Party Started: An Introduction to Git and GitHubKim Moir
 
Learn Git form Beginners to Master
Learn Git form Beginners to MasterLearn Git form Beginners to Master
Learn Git form Beginners to MasterC. M. Abdullah Khan
 
Git installation and configuration
Git installation and configurationGit installation and configuration
Git installation and configurationKishor Kumar
 
Essential git for developers
Essential git for developersEssential git for developers
Essential git for developersAidan Casey
 
Intro to git and git hub
Intro to git and git hubIntro to git and git hub
Intro to git and git hubVenkat Malladi
 
Introduction to Git and GitHub
Introduction to Git and GitHubIntroduction to Git and GitHub
Introduction to Git and GitHubVikram SV
 
WordPress and Git
WordPress and GitWordPress and Git
WordPress and GitRob Miller
 
An introduction to Git
An introduction to GitAn introduction to Git
An introduction to GitMuhil Vannan
 
Git with the flow
Git with the flowGit with the flow
Git with the flowDana White
 
Git One Day Training Notes
Git One Day Training NotesGit One Day Training Notes
Git One Day Training Notesglen_a_smith
 
Git workshop - University of Moratuwa, Department of Computer Science and Eng...
Git workshop - University of Moratuwa, Department of Computer Science and Eng...Git workshop - University of Moratuwa, Department of Computer Science and Eng...
Git workshop - University of Moratuwa, Department of Computer Science and Eng...WSO2
 
Git walkthrough
Git walkthroughGit walkthrough
Git walkthroughBimal Jain
 
True Git: The Great Migration
True Git: The Great MigrationTrue Git: The Great Migration
True Git: The Great Migrationcolleenfry
 

Similar to Git course level 2 (20)

Beginner's Guide to Version Control with Git
Beginner's Guide to Version Control with GitBeginner's Guide to Version Control with Git
Beginner's Guide to Version Control with Git
 
Let's Git this Party Started: An Introduction to Git and GitHub
Let's Git this Party Started: An Introduction to Git and GitHubLet's Git this Party Started: An Introduction to Git and GitHub
Let's Git this Party Started: An Introduction to Git and GitHub
 
Learn Git form Beginners to Master
Learn Git form Beginners to MasterLearn Git form Beginners to Master
Learn Git form Beginners to Master
 
Git installation and configuration
Git installation and configurationGit installation and configuration
Git installation and configuration
 
Essential git for developers
Essential git for developersEssential git for developers
Essential git for developers
 
Intro to git and git hub
Intro to git and git hubIntro to git and git hub
Intro to git and git hub
 
Introduction to Git and GitHub
Introduction to Git and GitHubIntroduction to Git and GitHub
Introduction to Git and GitHub
 
Git
GitGit
Git
 
WordPress and Git
WordPress and GitWordPress and Git
WordPress and Git
 
An introduction to Git
An introduction to GitAn introduction to Git
An introduction to Git
 
Git with the flow
Git with the flowGit with the flow
Git with the flow
 
git and github
git and githubgit and github
git and github
 
Mini git tutorial
Mini git tutorialMini git tutorial
Mini git tutorial
 
Git One Day Training Notes
Git One Day Training NotesGit One Day Training Notes
Git One Day Training Notes
 
Git workshop - University of Moratuwa, Department of Computer Science and Eng...
Git workshop - University of Moratuwa, Department of Computer Science and Eng...Git workshop - University of Moratuwa, Department of Computer Science and Eng...
Git workshop - University of Moratuwa, Department of Computer Science and Eng...
 
GIT In Detail
GIT In DetailGIT In Detail
GIT In Detail
 
Git-r-Done
Git-r-DoneGit-r-Done
Git-r-Done
 
Git walkthrough
Git walkthroughGit walkthrough
Git walkthrough
 
Learn Git Basics
Learn Git BasicsLearn Git Basics
Learn Git Basics
 
True Git: The Great Migration
True Git: The Great MigrationTrue Git: The Great Migration
True Git: The Great Migration
 

Recently uploaded

8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...kalichargn70th171
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024Mind IT Systems
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfVishalKumarJha10
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfproinshot.com
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionOnePlan Solutions
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 

Recently uploaded (20)

8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 

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 (DON’T 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 –m”New 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 (Don’t 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 (Don’t 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 wasn’t 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: • Don’t 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 ! (Don’t 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 don’t 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 –m”Squashed…” Terje Sandstrøm, Inmeta Consulting, 2014