Introduction to Git Ashley Roach, Dev Evangelist APIs and Cloud – DevNet Twitter: @aroach Email:
[email protected] DEVNET-1212
Agenda
•
Introduction
•
Quick overview of Git
•
Workshop
•
Resources
WHY ARE WE HERE?
Twitter: @aroach
developer.cisco.com
DEVNET-1212
© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public
4
Why version control? To Protect yourself and others
DISTRIBUTED VERSION CONTROL •
Opens up to new workflows: git flow
•
Each system has an exact replica of the repo as other collaborators.
https://git-scm.com/images/about/
[email protected] Twitter: @aroach
developer.cisco.com
DEVNET-1212
© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public
6
Under the hood •
Changes are stored in trees
•
Trees contain changed files
•
Commits contain trees
http://git-scm.com/figures/18333fig0903-tn.png Twitter: @aroach
developer.cisco.com
DEVNET-1212
© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public
7
GIT CONFIG •
So you can be held accountable, configure git
$ git config --global user.name "Your Name Comes Here" $ git config --global user.email
[email protected] Twitter: @aroach
developer.cisco.com
DEVNET-1212
© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public
8
GIT INIT •
Initializes a project directory with a hidden directory /.git/
$ tar xzf project.tar.gz $ cd project $ git init
Twitter: @aroach
developer.cisco.com
DEVNET-1212
© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public
9
GIT ADD •
Add any files in your repository to git “stage”
https://git-scm.com/images/about/
[email protected] $ git add .
Twitter: @aroach
developer.cisco.com
DEVNET-1212
© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public
10
STAGING AREA
Hat tip: @GeorgiaReh Twitter: @aroach
developer.cisco.com
DEVNET-1212
© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public
11
GIT COMMIT •
Store your changes into a commit
•
Saves all of your changes together / save point
•
Commit does NOT push
$ git commit –m ’Initial commit’
Twitter: @aroach
developer.cisco.com
DEVNET-1212
© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public
12
BRANCHING: Your safe place
$ $ $ $
•
Makes a pointer to your code
•
Moves HEAD around git git git git
branch branch testing commit –m “new” checkout master http://git-scm.com/figures/18333fig0307-tn.png
Twitter: @aroach
developer.cisco.com
DEVNET-1212
© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public
13
MERGING •
git merge
•
You must be on the branch you want to merge INTO when you execute this command (e.g. master)
$ git merge
Twitter: @aroach
developer.cisco.com
DEVNET-1212
© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public
14
GOING BACKWARDS •
Generate a new commit that undoes all of the changes introduced in , then apply it to the current branch.
$ git revert
Twitter: @aroach
developer.cisco.com
DEVNET-1212
© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public
15
SHARE YOUR CHANGES •
git push <destination>
•
git push origin master
$ git remote add $ git push $ git push origin master
Twitter: @aroach
developer.cisco.com
DEVNET-1212
© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public
16
CLONING PROJECTS (SSH OR HTTPS) •
No password
•
Set up SSH key on remote server (e.g. ssh-keygen)
$ git clone
[email protected]:aroach/upgraded-guacamole.git
$ git clone https://github.com/aroach/upgraded-guacamole.git
Twitter: @aroach
developer.cisco.com
DEVNET-1212
© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public
17
GIT CLIENTS •
CLI Client
•
IDE Clients • •
•
VIM: airblade/vim-gitgutter Emacs: magit
GUI Clients • •
SourceTree Git Kracken
Twitter: @aroach
developer.cisco.com
DEVNET-1212
© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public
18
Workshop
Let’s get started
http://bit.ly/devnet-git-intro
Twitter: @aroach
developer.cisco.com
DEVNET-1212
© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public
20
Additional Resources •
https://training.github.com/kit/downloads/github-git-cheat-sheet.pdf
•
https://www.atlassian.com/git/tutorials/comparing-workflows/
Twitter: @aroach
developer.cisco.com
DEVNET-1212
© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public
21
Contact •
Ashley Roach
•
[email protected] •
@aroach
Twitter: @aroach
developer.cisco.com
DEVNET-1212
© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public
22
Complete Your Online Session Evaluation •
Please complete your Online Session Evaluations after each session
•
Complete 4 Session Evaluations & the Overall Conference Evaluation (available from Thursday) to receive your Cisco Live T-shirt
•
All surveys can be completed via the Cisco Live Mobile App or the Communication Stations
Twitter: @aroach
developer.cisco.com
Don’t forget: Cisco Live sessions will be available for viewing on-demand after the event at CiscoLive.com/Online
DEVNET-1212
© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public
23
Continue Your Education •
Demos in the Cisco campus
•
Walk-in Self-Paced Labs
•
Lunch & Learn
•
Meet the Engineer 1:1 meetings
•
Related sessions
Twitter: @aroach
developer.cisco.com
DEVNET-1212
© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public
24
Q&A
Thank You