intro to git and github ~ girl develop it ~ intro to git ...files.meetup.com/1798823/intro to git...

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

Upload: others

Post on 20-Jun-2020

64 views

Category:

Documents


0 download

TRANSCRIPT

INTRO TO GIT AND GITHUB

Intro to Git and Github ~ Girl Develop It ~ 

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

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

WHAT WE WILL COVERTODAY

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

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?

WORKING WITHOUTVERSION CONTROL

The Horror!

WORKING WITH VERSIONCONTROL

Rainbows and bunny rabbits!

BRIEF HISTORY OF VERSIONCONTROL

1990s ­­ CVS (Concurrent VersionSystems)

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

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.

VERSION CONTROLDISTRIBUTION

Version control share betweenBazaar, CVS, Git, Mercurial and

Subversion

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

Subversion

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

INSTALLATION AND SETUPInstall git

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]             

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]             

INSTALLATION AND SETUPAdd SSH Key to Github

INSTALLATION AND SETUP

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             

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             

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             

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."             

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

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.               

LOOK AT OUR PROGRESS,VISUALLY

NOBODY'S PERFECT

   gitk             

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               

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               

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]               

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               

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             

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

BRANCHING

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"             

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             

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             

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"             

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

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

CREATE YOUR FIRST REPOSITORY

GITHUBCREATE YOUR FIRST REPOSITORY

CREATE YOUR FIRST REPOSITORY

GITHUBREADME

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. ”

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             

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             

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             

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

FORKING

FORKINGCLONING

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             

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

PREVIEWING AND SENDINGPULL REQUEST

MANAGING PULL REQUESTSHow to manage pull requests is out of

the scope of this short workshop, but you

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

QUESTIONS?

?

Github Collaborating Tutorials

?