Practical Git - Philly.NET Code Camp
-
Upload
christopher-gomez -
Category
Software
-
view
78 -
download
4
Transcript of Practical Git - Philly.NET Code Camp
![Page 1: Practical Git - Philly.NET Code Camp](https://reader034.fdocuments.us/reader034/viewer/2022051521/587486bd1a28abc62f8b5877/html5/thumbnails/1.jpg)
Practical Gitat work and open source
Chris Gomez@SpaceShot
www.chrisgomez.com
Slide deck: http://bit.ly/phlcc16_git
![Page 2: Practical Git - Philly.NET Code Camp](https://reader034.fdocuments.us/reader034/viewer/2022051521/587486bd1a28abc62f8b5877/html5/thumbnails/2.jpg)
Chris Gomez• Microsoft MVP in Visual Studio Tools and Technologies• Co-host of the Static Void Podcast www.staticvoidpodcast.com• Philly Game Works - www.phillygameworks.org - @phillygameworks
![Page 3: Practical Git - Philly.NET Code Camp](https://reader034.fdocuments.us/reader034/viewer/2022051521/587486bd1a28abc62f8b5877/html5/thumbnails/3.jpg)
Git• Created by Linus Torvalds
https://www.youtube.com/watch?v=4XpnKHJAok8
![Page 4: Practical Git - Philly.NET Code Camp](https://reader034.fdocuments.us/reader034/viewer/2022051521/587486bd1a28abc62f8b5877/html5/thumbnails/4.jpg)
Goals• Suitable for Open Source collaboration• No central server, lack of connectivity to contributors• Don’t want to have to know and trust all the contributors• Intended for Linus to have a “web of trust” in dealing with Linux
• Something that is not CVS or SVN• Intense dislike of CVS and SVN• Top complaint seems to be “intelligent merging”• Also complaint that merge pain often fell on a victim rather than perpetrator
![Page 5: Practical Git - Philly.NET Code Camp](https://reader034.fdocuments.us/reader034/viewer/2022051521/587486bd1a28abc62f8b5877/html5/thumbnails/5.jpg)
It’s just a Directed Acyclic Graph!• A very complicated way of saying something very simple:
![Page 6: Practical Git - Philly.NET Code Camp](https://reader034.fdocuments.us/reader034/viewer/2022051521/587486bd1a28abc62f8b5877/html5/thumbnails/6.jpg)
http://xkcd.com/1597/
![Page 7: Practical Git - Philly.NET Code Camp](https://reader034.fdocuments.us/reader034/viewer/2022051521/587486bd1a28abc62f8b5877/html5/thumbnails/7.jpg)
Exploring the git filesystem• Content-Addressable filesystem• Objects are stored as blobs and identified by a hash of the content (plus a tiny
amount of header data)• Labels are placed somewhere else to link up our filenames
![Page 8: Practical Git - Philly.NET Code Camp](https://reader034.fdocuments.us/reader034/viewer/2022051521/587486bd1a28abc62f8b5877/html5/thumbnails/8.jpg)
Git repositories
SpaceShot/SignalR-BoardGame(on GitHub)*
* This could also be Visual Studio Team Services, BitBucket, your company’s git server, or any git repo on another server you have access to.
![Page 9: Practical Git - Philly.NET Code Camp](https://reader034.fdocuments.us/reader034/viewer/2022051521/587486bd1a28abc62f8b5877/html5/thumbnails/9.jpg)
Git clone
SpaceShot/SignalR-BoardGame(on GitHub)
C:\Source\SignalR-BoardGame(my computer)
Copy
![Page 10: Practical Git - Philly.NET Code Camp](https://reader034.fdocuments.us/reader034/viewer/2022051521/587486bd1a28abc62f8b5877/html5/thumbnails/10.jpg)
Git clone
SpaceShot/SignalR-BoardGame
C:\Source\SignalR-BoardGame
Each is a fully independent repository
![Page 11: Practical Git - Philly.NET Code Camp](https://reader034.fdocuments.us/reader034/viewer/2022051521/587486bd1a28abc62f8b5877/html5/thumbnails/11.jpg)
“Fork”
SpaceShot/SignalR-BoardGame
Copies in the cloud (or your server)
phlgameworks/SignalR-BoardGame
Each is a fully independent repository
![Page 12: Practical Git - Philly.NET Code Camp](https://reader034.fdocuments.us/reader034/viewer/2022051521/587486bd1a28abc62f8b5877/html5/thumbnails/12.jpg)
“Fork”• Is Fork a Git concept?• GitHub / Bitbucket / Gitlab concept (and others)• Not in Visual Studio Team Services• Can be simulated with git commands, if necessary.
•Why fork?• Isolation of work• Freedom to experiment and commit• Not just with source control
![Page 13: Practical Git - Philly.NET Code Camp](https://reader034.fdocuments.us/reader034/viewer/2022051521/587486bd1a28abc62f8b5877/html5/thumbnails/13.jpg)
Git remotes
SpaceShot/SignalR-BoardGame
C:\Source\SignalR-BoardGame
Lightweight link to source
feature
Remotes
![Page 14: Practical Git - Philly.NET Code Camp](https://reader034.fdocuments.us/reader034/viewer/2022051521/587486bd1a28abc62f8b5877/html5/thumbnails/14.jpg)
git merge – putting two branches together
C1 C2
C3
C5C4
C6
C7
master
feature
Merge commit with two parents
master
![Page 15: Practical Git - Philly.NET Code Camp](https://reader034.fdocuments.us/reader034/viewer/2022051521/587486bd1a28abc62f8b5877/html5/thumbnails/15.jpg)
git rebase (onto a branch) – when the world moved on…
C1 C2
C3
C5C4
C6
C7
master
feature
![Page 16: Practical Git - Philly.NET Code Camp](https://reader034.fdocuments.us/reader034/viewer/2022051521/587486bd1a28abc62f8b5877/html5/thumbnails/16.jpg)
git rebase (onto a branch) – time travel your work
C1 C2 C3C5C4 C6C7
master
feature
![Page 17: Practical Git - Philly.NET Code Camp](https://reader034.fdocuments.us/reader034/viewer/2022051521/587486bd1a28abc62f8b5877/html5/thumbnails/17.jpg)
git rebase interactive – Why?
C1 C2
C3 C5C4 C6 C7
master
feature
![Page 18: Practical Git - Philly.NET Code Camp](https://reader034.fdocuments.us/reader034/viewer/2022051521/587486bd1a28abc62f8b5877/html5/thumbnails/18.jpg)
git rebase interactive – rewrite history
C1 C2
C3/C4 squashedC6 better commit
message C7
master
feature
C5 was dumped.Can rewrite commitsSquash commitsPick commits
![Page 19: Practical Git - Philly.NET Code Camp](https://reader034.fdocuments.us/reader034/viewer/2022051521/587486bd1a28abc62f8b5877/html5/thumbnails/19.jpg)
Other commands• Remove commits: git reset --hard HEAD~X• Change last commit message: git commit --amend• Track a branch: git remote add --track <branch> <remote
nickname> <remote address>• Git branch from a commit: git checkout –b <newbranch>
<commit>• Git cherry pick: git cherry-pick <commit>
![Page 20: Practical Git - Philly.NET Code Camp](https://reader034.fdocuments.us/reader034/viewer/2022051521/587486bd1a28abc62f8b5877/html5/thumbnails/20.jpg)
So advanced!• git filter-branch:
example:git filter-branch --tree-filter 'rm filename' HEAD
https://git-scm.com/docs/git-filter-branch
![Page 21: Practical Git - Philly.NET Code Camp](https://reader034.fdocuments.us/reader034/viewer/2022051521/587486bd1a28abc62f8b5877/html5/thumbnails/21.jpg)
But how are you really going to use Git?• You are probably going to use… a central server!
• You might use GitHub, BitBucket, Visual Studio Team Services in the cloud (among others)• You might use TFS on premises, GitLab, GitHub Enterprise,
BitBucket Enterprise
Wait, doesn’t this just make it SVN, CVS, TFS, VSS all over again?!?!
![Page 22: Practical Git - Philly.NET Code Camp](https://reader034.fdocuments.us/reader034/viewer/2022051521/587486bd1a28abc62f8b5877/html5/thumbnails/22.jpg)
To the Cloud!...
![Page 23: Practical Git - Philly.NET Code Camp](https://reader034.fdocuments.us/reader034/viewer/2022051521/587486bd1a28abc62f8b5877/html5/thumbnails/23.jpg)
libgit2• A reimplementation of Git in C with many bindings:• C#, Python, Ruby, Java• “re-entrant linkable library with a solid API”
• This means it’s okay to use it in your application. It is respectful of system resources and tries to keep from bringing down your application
https://libgit2.github.com/
![Page 24: Practical Git - Philly.NET Code Camp](https://reader034.fdocuments.us/reader034/viewer/2022051521/587486bd1a28abc62f8b5877/html5/thumbnails/24.jpg)
Some great resources
https://www.youtube.com/watch?v=SiokK8Q1wo0
https://www.youtube.com/watch?v=dBSHLb1B8sw
https://www.youtube.com/watch?v=duqBHik7nRo
![Page 25: Practical Git - Philly.NET Code Camp](https://reader034.fdocuments.us/reader034/viewer/2022051521/587486bd1a28abc62f8b5877/html5/thumbnails/25.jpg)
Git Man Page Generator (Fun)• https://git-man-page-generator.lokaltog.net/
• Please note this is not real git documentation, but a joke about Git documentation.