2016 MacAdmins - Using Git for Automation and...
-
Upload
truonghanh -
Category
Documents
-
view
267 -
download
2
Transcript of 2016 MacAdmins - Using Git for Automation and...
![Page 1: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/1.jpg)
U S I N G G I T F O R A U T O M AT I O N A N D C O L L A B O R AT I O N
J U S T I N E L L I O T T - M A T T H A N S E N P E N N S TA T E U N I V E R S I T Y
![Page 2: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/2.jpg)
A G E N D A
• Version control overview
• Introduction and basics of Git
• Advanced Git features
• Collaboration
• Automation
![Page 3: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/3.jpg)
V E R S I O N C O N T R O L
![Page 4: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/4.jpg)
W H AT I S I T ?
• Manages changes and versions of files
• Also known as:
• Source Code Management (SCM)
• Version Control System (VCS)
• GitHub is a hosting service that uses Git
![Page 5: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/5.jpg)
W H Y U S E I T ?
• Reduces risk and enables you to experiment with code
• Agility
• Flexible workflows
• Quicker deployments
• Automate updates
![Page 6: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/6.jpg)
W H Y U S E I T ?
• Helps with documentation
• Collaboration with others
• Contributing to open source projects
• Modifying a project for your own use
![Page 7: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/7.jpg)
G I T I N T R O D U C T I O N
![Page 8: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/8.jpg)
W H Y G I T ?
• The current de facto standard for source code management
• Easy to learn, quick to start!
• Very powerful and extensive
![Page 9: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/9.jpg)
G I T O V E R V I E W
• Extremely fast
• Excellent data integrity
• Git checksums everything (SHA-1)
![Page 10: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/10.jpg)
G I T O V E R V I E W
• Distributed
• All clients have the full repo
• Backups are everywhere
• Local repo updated before remotes
• When available, push updates to remote
![Page 11: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/11.jpg)
G I T T E R M I N O L O G Y
• Repository
• Local
• Remote
• Working Directory
• Commit
![Page 12: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/12.jpg)
G I T I N S TA L L AT I O N & C O N F I G U R AT I O N
![Page 13: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/13.jpg)
H O W T O I N S TA L L G I T
• Embedded with many Git GUI Apps
• Included with XCode
• Download from http://git-scm.com
• OS X: Terminal.app
• Windows: Git Bash
• Linux: Terminal
• OS X: MacPorts and HomeBrew
![Page 14: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/14.jpg)
G I T C L I E N T A P P S
• http://git-scm.com/downloads/guis
• GitHub Desktop
• https://desktop.github.com
• SourceTree
• https://www.sourcetreeapp.com
![Page 15: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/15.jpg)
R E V I E W I N G D I F F S
• Very easy to view with GitHub Desktop and Web
• External diff apps
• FileMerge
• Kaleidoscope
![Page 16: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/16.jpg)
G I T H U B D E S K T O P
• Simplifies the complex Git tasks
• Integrates well with GitHub hosting service
• Easy to start with
• Limited feature set (by design)
![Page 17: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/17.jpg)
D E M O : G I T H U B C O N F I G
![Page 18: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/18.jpg)
C O N F I G U R I N G G I T O N T H E C L I
• Git GUI clients handle it for you, or for the CLI fans …
• $ git config
• Contains items such as name, email, editor, diff tool
• Critical for collaboration
![Page 19: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/19.jpg)
D E M O : G I T C O N F I G C L I
https://asciinema.org/a/anjsg2tmlwul6j3ahizgl98ie
![Page 20: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/20.jpg)
F U N D A M E N TA L S
![Page 21: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/21.jpg)
R E P O F I L E C L A S S I F I C AT I O N S
• Tracked
• Ignored
• Untracked
![Page 22: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/22.jpg)
T R A C K E D F I L E S TAT E S
• Modified
• Staged
• GitHub Desktop shows as checkboxes
• Committed
![Page 23: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/23.jpg)
C R E AT E A R E P O
• Create new empty project repository
Working Directory
![Page 24: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/24.jpg)
• Add (stage) files for the next commit
A D D F I L E S T O T H E R E P O
Working Directory
Staging Areaadd
![Page 25: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/25.jpg)
C O M M I T F I L E S T O R E P O
Working Directory
Staging Areaadd
Repositorycommit
• Save staged files to the project repository
![Page 26: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/26.jpg)
C O M M I T S
• Saves file changes to the repo
• Each commit should encapsulate a single fix*
• Commit often - You will thank yourself later!
• Or else … Larger changes are much harder to pick apart and revert back to.
![Page 27: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/27.jpg)
I G N O R I N G F I L E S / D I R E C T O R I E S
• Why? • What? • How? • Scope
• Single Project Repo • All Repos ( Global ~/.gitignore_global file )
• Recommended to create ignore file as first step
![Page 28: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/28.jpg)
C O M M I T H I S T O R Y L O G S
• Review history of commits to repo
• Documents changes over time
• Extremely helpful for your future self and others
![Page 29: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/29.jpg)
D E M O
• Create repo
• Create files
• Show status
• Ignore file(s)
• Commit git ignore file
• Initial commit of file
• Modify same tracked file
• View diff of file changes
• Commit the file
• Review history log
• Revert to previous commit
• Review history log
![Page 30: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/30.jpg)
![Page 31: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/31.jpg)
B R A N C H E S
![Page 32: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/32.jpg)
B R A N C H E S
• Provide separate paths of code development
• When should they be used?
• Others to help test before merged to master
• “master” is the default branch
• Great for vetting major changes, for others to review
• Many workflow methods out there (ie, GitFlow)
![Page 33: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/33.jpg)
B R A N C H W A L K T H R O U G H
M 1
First Commit
![Page 34: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/34.jpg)
B R A N C H W A L K T H R O U G H
M 1
New Branch
B 1
![Page 35: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/35.jpg)
B R A N C H W A L K T H R O U G H
M 1
B 1 B 2
Second Branch Commit
![Page 36: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/36.jpg)
B R A N C H W A L K T H R O U G H
M 1
B 1 B 2 B 3
Third Branch Commit
![Page 37: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/37.jpg)
B R A N C H W A L K T H R O U G H
M 1
B 1 B 2 B 3 B 4
Fourth Branch Commit
![Page 38: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/38.jpg)
B R A N C H W A L K T H R O U G H
M 1
Merge Branch To Master
B 1 B 2 B 3 B 4
M 2
(Branch Deleted
After Merge)
![Page 39: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/39.jpg)
G I T ' S " H E A D " R E F E R E N C E
• Reference pointer to a commit
• “Detached HEAD” warning
• What does it mean?
• When does this occur?
• What should I do?
• Have code changes? Branch!
![Page 40: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/40.jpg)
B R A N C H W O R K F L O W S
• GitHub Flow
• Atlassian’s List
• Centralized
• Feature
• Git Flow
• Forking
![Page 41: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/41.jpg)
R E M O T E S
![Page 42: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/42.jpg)
R E M O T E S
• Local repo on your client only
• Remote is a Git host to push to
• You clone from remote(s)
• ie. GitHub, BitBucket
• First remote is called “origin”
• Avoid changing the remote name, some GUI Apps look for it
![Page 43: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/43.jpg)
R E M O T E R E P O S
• Network Protocols
• HTTPS
• SSH (Keys)
• Git Protocol (daemon)
![Page 44: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/44.jpg)
S E L F - H O S T E D R E P O S E R V I C E S
• SSH
• Enable SSH, create “bare” repository on server
• % git init --bare --shared
• Atlassian Stash
• Enterprise GitHub
• GitLab
![Page 45: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/45.jpg)
H O S T E D R E P O S E R V I C E S
• GitHub, BitBucket
• SourceRepo, Assembla
• GitLab
• git.psu.edu for Penn Staters (runs on GitLab)
• And many more …
![Page 46: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/46.jpg)
G I T W O R K F L O W S TA G E S
Working Directory
Staging Areaadd
Repositorycommit
Remotepushpull
![Page 47: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/47.jpg)
C L O N I N G
• Copies repo from remote
• Repo includes entire project
![Page 48: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/48.jpg)
P U S H I N G
• Saves commits to remote server
• Pushes active branch that you’re on
![Page 49: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/49.jpg)
F E T C H I N G
• Updates repo status of remote
• Local repo files are not changed
• Always fetch or pull before pushing to remotes!
![Page 50: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/50.jpg)
R E M O T E S - D O ' S A N D D O N ' T S
• Do...
• Always fetch or pull before making changes
• Otherwise you will need to merge or rebase your changes
• Don't...
• Make changes to local repo before fetching/pulling, or else create a new branch first
• OR stash the files first
![Page 51: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/51.jpg)
R E M O T E S D E M O
• Add local repo to GitHub Desktop
• Publish to GitHub
• View new remote host via “git remote -vv”
• View tracking branch(es) via “git branch -vv”
• Local branches track remote branches
• Commit first to local, then push to GitHub
• Create README.md file on GitHub, Pull
![Page 52: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/52.jpg)
![Page 53: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/53.jpg)
C O L L A B O R AT I O N
![Page 54: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/54.jpg)
E T I Q U E T T E
• Pull Request vs. Feature Requests
• Read the project's docs and guidelines first
• Start with simple changes to learn processes
• Avoid pull requests on pull requests
• Instead, provide feedback to author of pull for additional fixes or suggestions
![Page 55: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/55.jpg)
E T I Q U E T T E
• Commit Messages
• Keep them small, clear and descriptive
• Remember others need to understand them
• Stick to the project's coding styles and conventions
• Follow or establish team decided branch workflow
• Be nice!
![Page 56: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/56.jpg)
C R E AT I N G A P U L L R E Q U E S T
Their Remote Repo
Your Remote Repofork
Local Repositoryclone/pull
Working Copy
commit
Pull Request
mergepush
Discussion
Contributor
![Page 57: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/57.jpg)
G I T H U B P U L L R E Q U E S T
![Page 58: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/58.jpg)
R E C E I V I N G A P U L L R E Q U E S T
• Discuss and gather feedback
![Page 59: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/59.jpg)
R E C E I V I N G A P U L L R E Q U E S T
• Squash & merge or Merge commit
![Page 60: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/60.jpg)
R E C E I V I N G A P U L L R E Q U E S T
• Checkout and test
![Page 61: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/61.jpg)
A U T O M AT I O N
![Page 62: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/62.jpg)
I N T E G R AT I O N S
• Automatic emails
• Push notifications
• Slack Channels, IRC, Twitter, HipChat, etc.
• Methods
• WebHooks
• Agents / Runners
• Polling
![Page 63: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/63.jpg)
A U T O M AT I O N T O O L S
• Scripts
• launchd, cron to automate git pulls
• AutoPkgr schedule for autopkg recipe repos
• Continuous Integration
• Jenkins, Atlassian Bamboo, GitLab
• Travis CI
![Page 64: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/64.jpg)
W E B H O O K S
• Receive event notifications between multiple systems
• commit, push (tag or branch), releases, issues, documentation updates, forks, etc.
• Useful for updating, notifying, building, testing, backing up, deploying
![Page 65: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/65.jpg)
A U T O M AT I O N I D E A S
• Auto update servers (Web, etc.)
• Revert to previous commit
• Example
• Agent/Runner runs script after repo receives commit
• Automated testing, build and test products/recipes
![Page 66: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/66.jpg)
A U T O M AT E D W O R K F L O W S
• Update server content from master branch
• Auto pull “ready for production” versions
• Track changes made on servers, switches
• .git folder security issue - be aware
![Page 67: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/67.jpg)
C L C C A S E S T U D Y
autopkg
GitLab GitHub
BigFix
Jenkins
Slack
![Page 68: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/68.jpg)
C L C C A S E S T U D Y
• Lessons Learned
• Use the tool that works best
• Keep it simple and robust
• Lots of notifications, categorized and specific
• Working with internal and external collaborators
• Leverage the features of Git - commits, events, builds
![Page 69: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/69.jpg)
S U M M A R Y
![Page 70: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/70.jpg)
L E S S O N S L E A R N E D
• Start small
• Pick just one project to manage with Git
• Use remotes when ready
• GitHub, BitBucket
• Your own SSH host
![Page 71: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/71.jpg)
L E S S O N S L E A R N E D
• Write good commit messages
• There will be a time when you need to search your commit messages and it will really help you out!
• Be nice to your future self.
• “Where / when / how did I fix that issue?”
• What’s for the release notes?
![Page 72: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/72.jpg)
L E S S O N S L E A R N E D
• Keep it simple
• Don't be afraid to experiment
• Automation and integrations are powerful
• Use them after you're comfortable with the basics
![Page 73: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/73.jpg)
R E S O U R C E S A N D T R A I N I N G
• http://bit.ly/psumac-git-cs
• Official Git Site
• http://git-scm.com
• Git Cheat Sheets
• Git Pro Book
• bit.ly/psumac-nice-pulls
![Page 74: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/74.jpg)
R E S O U R C E S A N D T R A I N I N G
• http://try.github.com - learn Git in 15 minutes!
• http://atlassian.com/git
• http://bit.ly/psumac-git-wf
• O’Reilly
• “McCullough and Berglund on Mastering Git”
![Page 75: 2016 MacAdmins - Using Git for Automation and Collaborationmacadmins.psu.edu/.../2016/...Git-for-Automation-and-Collaboration.pdf · USING GIT FOR AUTOMATION AND COLLABORATION ...](https://reader033.fdocuments.us/reader033/viewer/2022052300/5a7e6c587f8b9a563b8e8b3b/html5/thumbnails/75.jpg)
Justin Elliott jelliott [at] psu.edu
@justindelliott
Matt Hansen hansen.m [at] psu.edu
@hansen_m
Feedback: https://bit.ly/psumac2016-91
Q & A