Essential git for developers
-
Upload
aidan-casey -
Category
Technology
-
view
626 -
download
1
description
Transcript of Essential git for developers
![Page 1: Essential git for developers](https://reader036.fdocuments.in/reader036/viewer/2022081412/540690fc8d7f7288088b460e/html5/thumbnails/1.jpg)
Essential Git For Developers
CORK ALT.NET DECEMBER 2013
![Page 2: Essential git for developers](https://reader036.fdocuments.in/reader036/viewer/2022081412/540690fc8d7f7288088b460e/html5/thumbnails/2.jpg)
What is Git?Distributed version control system
Open source ,written in C
Linus Torvalds 2005 to maintain the linux kernel
![Page 3: Essential git for developers](https://reader036.fdocuments.in/reader036/viewer/2022081412/540690fc8d7f7288088b460e/html5/thumbnails/3.jpg)
Why Git?•Focuses on content not files
•Opt in when it comes to commits
•Open, not closed– open source model of working is baked into the software
•Distributed - works almost entirely offline
•It changes how you work – commit more often, making code reviews easier
•Browsing history is lightening fast
•Non-linear development
![Page 4: Essential git for developers](https://reader036.fdocuments.in/reader036/viewer/2022081412/540690fc8d7f7288088b460e/html5/thumbnails/4.jpg)
Centralized vs. DistributedCentralised DistributedHistory only on the server Complete history of the repo locally
Commit changes online only Nearly every operation is local (offline) you can commit locally & branch locally
Down tools if server is down No hassle if server is down, redundant by default
Branching is difficult Branching is really easy & lightweightBranching is no longer a dirty word
Everyone commits to main repo ,typically you check in when your work is complete
More flexible workflows, you commit changes more regularly
![Page 5: Essential git for developers](https://reader036.fdocuments.in/reader036/viewer/2022081412/540690fc8d7f7288088b460e/html5/thumbnails/5.jpg)
Demo – create a repo and add some files
![Page 6: Essential git for developers](https://reader036.fdocuments.in/reader036/viewer/2022081412/540690fc8d7f7288088b460e/html5/thumbnails/6.jpg)
Commands• $git init• $git add <fileName>• $git commit –m <commit message>• $git status• $git log• $git command --help
![Page 7: Essential git for developers](https://reader036.fdocuments.in/reader036/viewer/2022081412/540690fc8d7f7288088b460e/html5/thumbnails/7.jpg)
StagingWorking Directory
Staging Area
Repository
git add
git commit
![Page 8: Essential git for developers](https://reader036.fdocuments.in/reader036/viewer/2022081412/540690fc8d7f7288088b460e/html5/thumbnails/8.jpg)
File Status
stackoverflow.com/questions/15653066/how-to-track-but-not-stage-and-how-to-unstage-but-not-untrack
![Page 9: Essential git for developers](https://reader036.fdocuments.in/reader036/viewer/2022081412/540690fc8d7f7288088b460e/html5/thumbnails/9.jpg)
Git stores snapshots, not differences
git-scm.com/book/en/Getting-Started-Git-Basics
![Page 10: Essential git for developers](https://reader036.fdocuments.in/reader036/viewer/2022081412/540690fc8d7f7288088b460e/html5/thumbnails/10.jpg)
Demo – working with remotes
![Page 11: Essential git for developers](https://reader036.fdocuments.in/reader036/viewer/2022081412/540690fc8d7f7288088b460e/html5/thumbnails/11.jpg)
Commands• $git remote add <name> <url>• $git push <remote name> <local branch name>• $git clone <path to repo>
![Page 12: Essential git for developers](https://reader036.fdocuments.in/reader036/viewer/2022081412/540690fc8d7f7288088b460e/html5/thumbnails/12.jpg)
Git on the Server Protocols –SSH , HTTP
◦ HTTP - slower but allows anonymous access to the files◦ SSH - faster but everyone needs a unique SSH key
Hosting Options
◦ Self Hosted (GitLab CE)◦ GitHub, BitBucket & many more …
![Page 13: Essential git for developers](https://reader036.fdocuments.in/reader036/viewer/2022081412/540690fc8d7f7288088b460e/html5/thumbnails/13.jpg)
Demo – web hook integration
![Page 14: Essential git for developers](https://reader036.fdocuments.in/reader036/viewer/2022081412/540690fc8d7f7288088b460e/html5/thumbnails/14.jpg)
$git pull command
$git fetch + $git merge = $git pull
![Page 15: Essential git for developers](https://reader036.fdocuments.in/reader036/viewer/2022081412/540690fc8d7f7288088b460e/html5/thumbnails/15.jpg)
.gitignore fileTells git to ignore specific files / folders
https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
![Page 16: Essential git for developers](https://reader036.fdocuments.in/reader036/viewer/2022081412/540690fc8d7f7288088b460e/html5/thumbnails/16.jpg)
Branching• Think of a branch as simply a movable pointer to one of the commits in your
repository
• $git branch < new branchname >• $git checkout <branchname>• $git merge <branchname>
![Page 17: Essential git for developers](https://reader036.fdocuments.in/reader036/viewer/2022081412/540690fc8d7f7288088b460e/html5/thumbnails/17.jpg)
Fast forward mergeBefore merging After merge
![Page 18: Essential git for developers](https://reader036.fdocuments.in/reader036/viewer/2022081412/540690fc8d7f7288088b460e/html5/thumbnails/18.jpg)
3 way mergeBefore merging After merge
![Page 19: Essential git for developers](https://reader036.fdocuments.in/reader036/viewer/2022081412/540690fc8d7f7288088b460e/html5/thumbnails/19.jpg)
Demo – branching and merging
![Page 20: Essential git for developers](https://reader036.fdocuments.in/reader036/viewer/2022081412/540690fc8d7f7288088b460e/html5/thumbnails/20.jpg)
Git-Flow•Vincent Driessen's branching model
•Defines a branching model designed around the project release, suitable for managing larger projects / large teams
![Page 21: Essential git for developers](https://reader036.fdocuments.in/reader036/viewer/2022081412/540690fc8d7f7288088b460e/html5/thumbnails/21.jpg)
TIME
![Page 22: Essential git for developers](https://reader036.fdocuments.in/reader036/viewer/2022081412/540690fc8d7f7288088b460e/html5/thumbnails/22.jpg)
Rebasing“Take my commits and replay them after the HEAD of another branch.”
• take all the changes that were committed on one branch and replay them on another one.
• Moves a branch to a new base commit
• Completely rewrites history!
• Don’t do this on a shared branch
![Page 23: Essential git for developers](https://reader036.fdocuments.in/reader036/viewer/2022081412/540690fc8d7f7288088b460e/html5/thumbnails/23.jpg)
MERGE RESULT
REBASE RESULT
![Page 24: Essential git for developers](https://reader036.fdocuments.in/reader036/viewer/2022081412/540690fc8d7f7288088b460e/html5/thumbnails/24.jpg)
Forking & Pull Requests
![Page 25: Essential git for developers](https://reader036.fdocuments.in/reader036/viewer/2022081412/540690fc8d7f7288088b460e/html5/thumbnails/25.jpg)
Demo – exploring the repo history
![Page 26: Essential git for developers](https://reader036.fdocuments.in/reader036/viewer/2022081412/540690fc8d7f7288088b460e/html5/thumbnails/26.jpg)
Debugging git blame
$git blame [-L ine1,line2]] <file>
• Lets you see when each line of a method was edited and by whom
![Page 27: Essential git for developers](https://reader036.fdocuments.in/reader036/viewer/2022081412/540690fc8d7f7288088b460e/html5/thumbnails/27.jpg)
Debugging git bisect
$ git bisect start$ git bisect bad HEAD$ git bisect good 1b6d
![Page 28: Essential git for developers](https://reader036.fdocuments.in/reader036/viewer/2022081412/540690fc8d7f7288088b460e/html5/thumbnails/28.jpg)
Cherry Picking
$git cherry-pick <sha-1_commit>
If you want to get one single commit out of a branch
![Page 29: Essential git for developers](https://reader036.fdocuments.in/reader036/viewer/2022081412/540690fc8d7f7288088b460e/html5/thumbnails/29.jpg)
Git on Windows GUI Clients
SourceTree (free)
GitHub for Windows
Git GUI for Windows
TortoiseGit
Shells
Bash
Posh-git
Powershell
Cmd
![Page 30: Essential git for developers](https://reader036.fdocuments.in/reader036/viewer/2022081412/540690fc8d7f7288088b460e/html5/thumbnails/30.jpg)
Advice for getting started•Learning curve
•Start with the command line, not the GUI
• Agree a good branch strategy with your team up front
• (Almost) every should be short lived, and kept up to date with master
•Commit often, perfect later & user meaningful commit messages
![Page 31: Essential git for developers](https://reader036.fdocuments.in/reader036/viewer/2022081412/540690fc8d7f7288088b460e/html5/thumbnails/31.jpg)
Thanks for listening!
twitter : @AIDANJCASEY