Top Banner
INTRO TO GIT AND GITHUB Intro to Git and Github ~ Girl Develop It ~
49

Intro to Git and Github ~ Girl Develop It ~ INTRO TO GIT ...files.meetup.com/1798823/Intro to Git and Github _ Girl Develop It.pdf · When we add a new file, we tell Git to add the

Jun 20, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Intro to Git and Github ~ Girl Develop It ~ INTRO TO GIT ...files.meetup.com/1798823/Intro to Git and Github _ Girl Develop It.pdf · When we add a new file, we tell Git to add the

INTRO TO GIT AND GITHUB

Intro to Git and Github ~ Girl Develop It ~ 

Page 2: Intro to Git and Github ~ Girl Develop It ~ INTRO TO GIT ...files.meetup.com/1798823/Intro to Git and Github _ Girl Develop It.pdf · When we add a new file, we tell Git to add the

WELCOME!Girl Develop It is here to provideaffordable and accessible programs tolearn software through mentorship andhands­on instruction.Some "rules"We are here for you!Every question is importantHelp each otherHave fun

Page 3: Intro to Git and Github ~ Girl Develop It ~ INTRO TO GIT ...files.meetup.com/1798823/Intro to Git and Github _ Girl Develop It.pdf · When we add a new file, we tell Git to add the

WELCOME!Tell us about yourself.Who are you?What do you hope to get out of theclass?Who was your favorite character as achild?

Page 4: Intro to Git and Github ~ Girl Develop It ~ INTRO TO GIT ...files.meetup.com/1798823/Intro to Git and Github _ Girl Develop It.pdf · When we add a new file, we tell Git to add the

WHAT WE WILL COVERTODAY

What is version control and whyshould we care?Basics of git ­­ the essentialcommands"Gitting" social with GitHub

Page 5: Intro to Git and Github ~ Girl Develop It ~ INTRO TO GIT ...files.meetup.com/1798823/Intro to Git and Github _ Girl Develop It.pdf · When we add a new file, we tell Git to add the

WHAT IS VERSIONCONTROL?

Version control allows you (and yourteam) to do two powerful things

COLLABORATECreate anything with other people, fromacademic papers to entire websites and

applications.TRACK AND REVERT CHANGES

Mistakes happen. Wouldn't it be nice ifyou could see the changes that havebeen made and go "back in time" to fix

something that went wrong?

Page 6: Intro to Git and Github ~ Girl Develop It ~ INTRO TO GIT ...files.meetup.com/1798823/Intro to Git and Github _ Girl Develop It.pdf · When we add a new file, we tell Git to add the

WORKING WITHOUTVERSION CONTROL

The Horror!

Page 7: Intro to Git and Github ~ Girl Develop It ~ INTRO TO GIT ...files.meetup.com/1798823/Intro to Git and Github _ Girl Develop It.pdf · When we add a new file, we tell Git to add the

WORKING WITH VERSIONCONTROL

Rainbows and bunny rabbits!

Page 8: Intro to Git and Github ~ Girl Develop It ~ INTRO TO GIT ...files.meetup.com/1798823/Intro to Git and Github _ Girl Develop It.pdf · When we add a new file, we tell Git to add the

BRIEF HISTORY OF VERSIONCONTROL

1990s ­­ CVS (Concurrent VersionSystems)

2000s ­­ SVN (Apache Subversion)2005 ­­ Git (well, Git)

Page 9: Intro to Git and Github ~ Girl Develop It ~ INTRO TO GIT ...files.meetup.com/1798823/Intro to Git and Github _ Girl Develop It.pdf · When we add a new file, we tell Git to add the

VERSION CONTROL TYPESCENTRALIZED VERSION CONTROL

Examples: CVS, SVNOne central server, each client (person)checks out and merges changes to main

serverDISTRIBUTED VERSION CONTROL

Examples: Git, MercurialEach client (person) has a local

repository, which they can then reconcilewith the main server.

Page 10: Intro to Git and Github ~ Girl Develop It ~ INTRO TO GIT ...files.meetup.com/1798823/Intro to Git and Github _ Girl Develop It.pdf · When we add a new file, we tell Git to add the

VERSION CONTROLDISTRIBUTION

Version control share betweenBazaar, CVS, Git, Mercurial and

Subversion

Page 11: Intro to Git and Github ~ Girl Develop It ~ INTRO TO GIT ...files.meetup.com/1798823/Intro to Git and Github _ Girl Develop It.pdf · When we add a new file, we tell Git to add the

VERSION CONTROL CHANGEVersion control popularity changebetween 2010 and 2013 betweenBazaar, CVS, Git, Mercurial and

Subversion

Page 12: Intro to Git and Github ~ Girl Develop It ~ INTRO TO GIT ...files.meetup.com/1798823/Intro to Git and Github _ Girl Develop It.pdf · When we add a new file, we tell Git to add the

INTRO TO GITGoals of Git Design

Fast ­­ add to your team and codebase quicklyDistributed (see slide above)Each commit has a correspondinghash (track changes from everyone)Everyone has a local copy of thehistory

Page 13: Intro to Git and Github ~ Girl Develop It ~ INTRO TO GIT ...files.meetup.com/1798823/Intro to Git and Github _ Girl Develop It.pdf · When we add a new file, we tell Git to add the

INSTALLATION AND SETUPInstall git

Page 14: Intro to Git and Github ~ Girl Develop It ~ INTRO TO GIT ...files.meetup.com/1798823/Intro to Git and Github _ Girl Develop It.pdf · When we add a new file, we tell Git to add the

INSTALLATION AND SETUPSetup ssh keys

              $ cd ~/.ssh             

 $ ssh‐keygen ‐t rsa ‐C "[email protected]" # Generating public/private rsa key pair. # Enter file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter]             

 Enter passphrase (empty for no passphrase): [Type a passphrase] # Enter same passphrase again: [Type passphrase again]             

Page 15: Intro to Git and Github ~ Girl Develop It ~ INTRO TO GIT ...files.meetup.com/1798823/Intro to Git and Github _ Girl Develop It.pdf · When we add a new file, we tell Git to add the

INSTALLATION AND SETUPGet SSH Key

 Your identification has been saved in /Users/you/.ssh/id_rsa. # Your public key has been saved in /Users/you/.ssh/id_rsa.pub. # The key fingerprint is: # 01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db [email protected]             

Page 16: Intro to Git and Github ~ Girl Develop It ~ INTRO TO GIT ...files.meetup.com/1798823/Intro to Git and Github _ Girl Develop It.pdf · When we add a new file, we tell Git to add the

INSTALLATION AND SETUPAdd SSH Key to Github

INSTALLATION AND SETUP

Page 17: Intro to Git and Github ~ Girl Develop It ~ INTRO TO GIT ...files.meetup.com/1798823/Intro to Git and Github _ Girl Develop It.pdf · When we add a new file, we tell Git to add the

INSTALLATION AND SETUPSetup name and email in gitconfig

YOUR FIRST LOCAL

 $ git config ‐‐global user.name "Your Name Here" # Sets the default name for git to use when you commit             

 $ git config ‐‐global user.email "[email protected]" # Sets the default email for git to use when you commit             

 $ git config ‐‐list             

Page 18: Intro to Git and Github ~ Girl Develop It ~ INTRO TO GIT ...files.meetup.com/1798823/Intro to Git and Github _ Girl Develop It.pdf · When we add a new file, we tell Git to add the

YOUR FIRST LOCALREPOSITORYGo to home directory

Create a "working directory"

Initialize repository with Git

ADD FILES

   cd ~/   OR   cd Users\username             

   mkdir my‐first‐repo   cd my‐first‐repo             

   git init   git status             

Page 19: Intro to Git and Github ~ Girl Develop It ~ INTRO TO GIT ...files.meetup.com/1798823/Intro to Git and Github _ Girl Develop It.pdf · When we add a new file, we tell Git to add the

ADD FILESCreate a new hello_world.txt file in your

new folderCheck repo status

Tell Git to track our new file

File is now tracked by Git

CHANGES AND COMMITS

   git status             

   git add hello_world.txt   git status             

Page 20: Intro to Git and Github ~ Girl Develop It ~ INTRO TO GIT ...files.meetup.com/1798823/Intro to Git and Github _ Girl Develop It.pdf · When we add a new file, we tell Git to add the

CHANGES AND COMMITSOpen hello_world.txt and add some

more text

Stage and commit the change

WHAT DID WE JUST DO??

   git status             

   git add hello_world.txt   git commit ‐m "First commit. Added hello world to repository."             

Page 21: Intro to Git and Github ~ Girl Develop It ~ INTRO TO GIT ...files.meetup.com/1798823/Intro to Git and Github _ Girl Develop It.pdf · When we add a new file, we tell Git to add the

WHAT DID WE JUST DO??How is this all different than just saving a

file?When we add a new file, we tell Git toadd the file to the repository to betrackedWhen we stage an existing file (alsowith the keyword 'add'), we are tellingGit to track the current state of our fileA commit saves changes made to afile, not the file as a whole. Thecommit will have a 'hash' so we cantrack which changes were committedwhen and by whom.

LOOK AT OUR PROGRESS

Page 22: Intro to Git and Github ~ Girl Develop It ~ INTRO TO GIT ...files.meetup.com/1798823/Intro to Git and Github _ Girl Develop It.pdf · When we add a new file, we tell Git to add the

LOOK AT OUR PROGRESS

LOOK AT OUR PROGRESS,

   git log             

   commit [HASH HERE]   Author: Your name    Date:   [DATE HERE]        First commit. Added hello world to repository.               

Page 23: Intro to Git and Github ~ Girl Develop It ~ INTRO TO GIT ...files.meetup.com/1798823/Intro to Git and Github _ Girl Develop It.pdf · When we add a new file, we tell Git to add the

LOOK AT OUR PROGRESS,VISUALLY

NOBODY'S PERFECT

   gitk             

Page 24: Intro to Git and Github ~ Girl Develop It ~ INTRO TO GIT ...files.meetup.com/1798823/Intro to Git and Github _ Girl Develop It.pdf · When we add a new file, we tell Git to add the

NOBODY'S PERFECTUNDOING LOCAL CHANGES

If you haven't committed yetOpen hello_world.txt and add some new

text

Look at hello_world.txt. Your changesare gone.

NOBODY'S PERFECT

   change hello_world.txt   git checkout hello_world.txt               

Page 25: Intro to Git and Github ~ Girl Develop It ~ INTRO TO GIT ...files.meetup.com/1798823/Intro to Git and Github _ Girl Develop It.pdf · When we add a new file, we tell Git to add the

NOBODY'S PERFECTUNDOING STAGED CHANGES

Open hello_world.txt and add some newtext

Look at hello_world.txt. Your changesare gone.

NOBODY'S PERFECT

 git add hello_world.txt git reset HEAD hello_world.txt git checkout hello_world.txt               

Page 26: Intro to Git and Github ~ Girl Develop It ~ INTRO TO GIT ...files.meetup.com/1798823/Intro to Git and Github _ Girl Develop It.pdf · When we add a new file, we tell Git to add the

NOBODY'S PERFECTUNDOING STAGED CHANGES

Open hello_world.txt and add some newtext

Look at hello_world.txt. Your changesare gone.

NOBODY'S PERFECT

 git add hello_world.txt git commit ‐am "Changing and committing some lines" git log ‐‐pretty=oneline git revert [HASH]               

Page 27: Intro to Git and Github ~ Girl Develop It ~ INTRO TO GIT ...files.meetup.com/1798823/Intro to Git and Github _ Girl Develop It.pdf · When we add a new file, we tell Git to add the

NOBODY'S PERFECTREMOVE A FILE FROM STAGING

Create new file my_new_file.txt

NOBODY'S PERFECT

 git add my_new_file.txt git reset my_new_file.txt               

Page 28: Intro to Git and Github ~ Girl Develop It ~ INTRO TO GIT ...files.meetup.com/1798823/Intro to Git and Github _ Girl Develop It.pdf · When we add a new file, we tell Git to add the

NOBODY'S PERFECTDELETE A FILE

Create new file my_other_file.txt

Manually delete your file

BRANCHING

 git add my_other_file.txt             

 git rm my_other_file.txt             

Page 29: Intro to Git and Github ~ Girl Develop It ~ INTRO TO GIT ...files.meetup.com/1798823/Intro to Git and Github _ Girl Develop It.pdf · When we add a new file, we tell Git to add the

BRANCHINGDevelop different code on the samebaseConduct exploratory work withoutaffecting the work on master branchIncorporate changes to your masterbranch only when you are ready

BRANCHING

Page 30: Intro to Git and Github ~ Girl Develop It ~ INTRO TO GIT ...files.meetup.com/1798823/Intro to Git and Github _ Girl Develop It.pdf · When we add a new file, we tell Git to add the

BRANCHINGCreate a new branch called version2

Add new lines to hello_world.txt

BRANCHING

 git checkout ‐b version2             

 git add hello_world.txt git commit ‐m "Adding changes to version 2"             

Page 31: Intro to Git and Github ~ Girl Develop It ~ INTRO TO GIT ...files.meetup.com/1798823/Intro to Git and Github _ Girl Develop It.pdf · When we add a new file, we tell Git to add the

BRANCHINGSWITCHING BRANCHES

See all branches. Branch with * is active

Switch to master and look athello_world.txt

Switch to version2 and look athello_world.txt

MERGING

 git branch             

 git checkout master             

 git checkout version2             

Page 32: Intro to Git and Github ~ Girl Develop It ~ INTRO TO GIT ...files.meetup.com/1798823/Intro to Git and Github _ Girl Develop It.pdf · When we add a new file, we tell Git to add the

MERGINGMERGE TO GET CHANGES FROM ONE

BRANCH INTO ANOTHER*Switch to master and merge changes

*rebase is another option, but will not becovered in this workshop

MERGING

 git checkout master git merge version2             

Page 33: Intro to Git and Github ~ Girl Develop It ~ INTRO TO GIT ...files.meetup.com/1798823/Intro to Git and Github _ Girl Develop It.pdf · When we add a new file, we tell Git to add the

MERGINGMERGE CONFLICTS

Change first line in hello_world.txt inmaster branch

Change first line in hello_world.txt inversion2 branch

MERGING

 git add hello_world.txt git commit ‐m "Changing first line in master"             

 git checkout version2 # open hello_world.txt and change first line git add hello_world.txt git commit ‐m "Changing first line in version2"             

Page 34: Intro to Git and Github ~ Girl Develop It ~ INTRO TO GIT ...files.meetup.com/1798823/Intro to Git and Github _ Girl Develop It.pdf · When we add a new file, we tell Git to add the

MERGE CONFLICTS, CONT.Merge from master into version2

You will be notified of a conflict. Go to thefile and fix the problem. Then commit

your edits.

 git merge master             

GITHUB

Page 35: Intro to Git and Github ~ Girl Develop It ~ INTRO TO GIT ...files.meetup.com/1798823/Intro to Git and Github _ Girl Develop It.pdf · When we add a new file, we tell Git to add the

Launched in 2008Leader in Social CodingGitHub is a commercial site that allowsusers to host Git repositories publiclyand privatelyOpen source projects host or mirrortheir repositories on GitHubPost your own code for others to useor contribute toUse and learn from the code in otherpeople's repositories

GITHUBCREATE YOUR FIRST REPOSITORY

Page 36: Intro to Git and Github ~ Girl Develop It ~ INTRO TO GIT ...files.meetup.com/1798823/Intro to Git and Github _ Girl Develop It.pdf · When we add a new file, we tell Git to add the

CREATE YOUR FIRST REPOSITORY

GITHUBCREATE YOUR FIRST REPOSITORY

Page 37: Intro to Git and Github ~ Girl Develop It ~ INTRO TO GIT ...files.meetup.com/1798823/Intro to Git and Github _ Girl Develop It.pdf · When we add a new file, we tell Git to add the

CREATE YOUR FIRST REPOSITORY

GITHUBREADME

Page 38: Intro to Git and Github ~ Girl Develop It ~ INTRO TO GIT ...files.meetup.com/1798823/Intro to Git and Github _ Girl Develop It.pdf · When we add a new file, we tell Git to add the

README

GITHUBGET LOCAL REPOSITORY OF GITHUB REPO

“ While a README isn't arequired part of a GitHubrepository, it is a very good

idea to have one.READMEs are a great placeto describe your project oradd some documentation

such as how to install or useyour project. You might want

to include contactinformation ­ if your projectbecomes popular people will

want to help you out. ”

Page 39: Intro to Git and Github ~ Girl Develop It ~ INTRO TO GIT ...files.meetup.com/1798823/Intro to Git and Github _ Girl Develop It.pdf · When we add a new file, we tell Git to add the

GET LOCAL REPOSITORY OF GITHUB REPO

GITHUBPUSH TO GITHUB REPO

 cd ../ # Back in root directory mkdir hello‐github cd hello‐github git init git remote add origin [email protected]:username/NAME‐OF‐REPO git pull origin master             

Page 40: Intro to Git and Github ~ Girl Develop It ~ INTRO TO GIT ...files.meetup.com/1798823/Intro to Git and Github _ Girl Develop It.pdf · When we add a new file, we tell Git to add the

PUSH TO GITHUB REPOEdit the ReadMe file

Go look at your github repo online

GITHUBPULLING FROM REMOTE REPOSITORY

 git add README git commit ‐m "Updating readme file" git push origin master             

Page 41: Intro to Git and Github ~ Girl Develop It ~ INTRO TO GIT ...files.meetup.com/1798823/Intro to Git and Github _ Girl Develop It.pdf · When we add a new file, we tell Git to add the

PULLING FROM REMOTE REPOSITORYIf you are working with a team, you wantto make sure that you have everyone'schanges before pushing your changes to

the GitHub repo

FORKINGThere are MILLIONS of public

 # Commit local changes git commit ‐m "My latest commit" # Pull changes other people have made git pull origin master # Fix any conflicts (see merge conflicts above) and commit git commit ‐m "Fixing merging conflicts" # push local changes to GitHub git push origin master             

Page 42: Intro to Git and Github ~ Girl Develop It ~ INTRO TO GIT ...files.meetup.com/1798823/Intro to Git and Github _ Girl Develop It.pdf · When we add a new file, we tell Git to add the

There are MILLIONS of publicrepositories on GitHubIf you want to use or contribute to arepository, you can fork it.

FORKING

Page 43: Intro to Git and Github ~ Girl Develop It ~ INTRO TO GIT ...files.meetup.com/1798823/Intro to Git and Github _ Girl Develop It.pdf · When we add a new file, we tell Git to add the

FORKINGCLONING

Page 44: Intro to Git and Github ~ Girl Develop It ~ INTRO TO GIT ...files.meetup.com/1798823/Intro to Git and Github _ Girl Develop It.pdf · When we add a new file, we tell Git to add the

CLONINGClone to get a local repository of your

fork

PULL REQUESTSAfter you fork and clone a repository

 cd ../  git clone https://github.com/username/FORKED‐REPO‐NAME.git  cd FORKED‐REPO‐NAME  git remote add upstream https://github.com/original‐username/FORKED‐REPO‐NAME.git # Assigns the original repository to a remote called "upstream"  git fetch upstream # Pulls in changes not present in your local repository, without modifying your files             

Page 45: Intro to Git and Github ~ Girl Develop It ~ INTRO TO GIT ...files.meetup.com/1798823/Intro to Git and Github _ Girl Develop It.pdf · When we add a new file, we tell Git to add the

After you fork and clone a repositoryall pushed changes will go to your forkThese changes will not affect theoriginal repositoryIf you would like to get your changesto be incorporated into the originalrepo, you can submit a pull request

STARTING A PULL REQUEST

Page 46: Intro to Git and Github ~ Girl Develop It ~ INTRO TO GIT ...files.meetup.com/1798823/Intro to Git and Github _ Girl Develop It.pdf · When we add a new file, we tell Git to add the

PREVIEWING AND SENDINGPULL REQUEST

Page 47: Intro to Git and Github ~ Girl Develop It ~ INTRO TO GIT ...files.meetup.com/1798823/Intro to Git and Github _ Girl Develop It.pdf · When we add a new file, we tell Git to add the

MANAGING PULL REQUESTSHow to manage pull requests is out of

the scope of this short workshop, but you

Page 48: Intro to Git and Github ~ Girl Develop It ~ INTRO TO GIT ...files.meetup.com/1798823/Intro to Git and Github _ Girl Develop It.pdf · When we add a new file, we tell Git to add the

the scope of this short workshop, but youcan learn more from the 

QUESTIONS?

?

Github Collaborating Tutorials

Page 49: Intro to Git and Github ~ Girl Develop It ~ INTRO TO GIT ...files.meetup.com/1798823/Intro to Git and Github _ Girl Develop It.pdf · When we add a new file, we tell Git to add the

?