24
Git and GitHub.com

Git101

Embed Size (px)

DESCRIPTION

Intro to Git slide deck.Covers initial setup, git init, git add, git diff, git commit, pushing and pulling to repo on Github.

Citation preview

Page 1: Git101

Git and GitHub.com

Page 2: Git101

Git 101

• Git is a distributed revision control system

• Keeps track of changes made to one or more files over time

• Shows log messages of what changed and why

• Allows developers to share their changes easily

Page 3: Git101

Git Project Sections

Source: http://progit.org/book/ch1-3.html

Page 4: Git101

Git workflow

Modify Files

Stage FilesCommit Files

Page 5: Git101

Installing Git

• Covered in detail at http://progit.org/book/ch1-4.html

Page 6: Git101

Initial Setup

• git config --global user.name “John Doe”• git config --global user.email [email protected]

• git config --global core.editor emacs– By default, it uses GIT_EDITOR, VISUAL or EDITOR Environment

variables– Other editors are vi, mate -m, nano, etc

• git config --list– Shows your git settings

• See http://progit.org/book/ch1-5.html for more

Page 7: Git101

Getting help

• Most Git commands have help available

• git help commit• git help branch• git help tag

Page 8: Git101

Getting started with Git

• mkdir project_name• cd project_name• git init• echo “Hello” >> README

• git add README

• git commit -m ‘Initial commit’

Page 9: Git101

Getting started Lab

• Create a new directory

• Initialize git

• Create/Edit a file

• Add/Stage that file

• Commit the stage to your local repo

• Repeat

Page 10: Git101

Working with remote reposPublic RepoLocated on Server (Github)

Private RepoLocated on your local machine

git pull git push

Page 11: Git101

Signup with Github• https://github.com/signup/free

– You can skip SSH Public Key, we’ll come back to it

Page 12: Git101

Setup SSH Keys

• ssh-keygen -d

Page 13: Git101

Setup local SSH config

• If you don’t use your “default” ssh key for GitHub, you need to tell SSH to use your Github key

Page 14: Git101

Add SSH Key to GitHub

• https://github.com/account

Page 15: Git101

Create my_project repo(on Github.com)

• https://github.com/

Page 16: Git101

Add your pair to my_project repo(on Github.com)

• Click the Edit button or go to https://github.com/your-user-name/my_project/edit

We’ll use this later

Page 17: Git101

Add remote repo to your local repo

• cd my_project• git remote add origin [email protected]:your-user-name/my_project.git

• git push origin master– “

origin” is configurable name

– “origin” is convention for GitHub

• View changes at http://github.com/your-user-name/my_project

Page 18: Git101

Remote repos processPublic RepoLocated on Server (Github)

Private RepoLocated on your local machine

git push

Make file changesStage ChangesCommit Changes

git add filenamegit commit -m ‘…’ vi filename

Page 19: Git101

Commit changes and push to remote repo

• cd my_project• echo “bye” >> README• git add README• git commit -m ‘Added bye to README’

• git push origin masterOR

• git push

• View changes at http://github.com/your-user-name/my_project

Page 20: Git101

Lab with remote repos(on Github.com)

• Modify file locally

• Add/Stage that file to the commit

• Commit your changes

• Push those changes to GitHub

Page 21: Git101

Remote repos process(multiple committers)

Public RepoLocated on Server (Github)

Private RepoLocated on your local machine

1) git push

Make file changesStage ChangesCommit Changes

git add filenamegit commit -m ‘…’ vi filename

Bob’s Private RepoLocated on Bob’s local machine

2) git pull

Page 22: Git101

Remote repos process(multiple committers)

Public RepoLocated on Server (Github)

Private RepoLocated on your local machine

2) git pull

Bob’s Private RepoLocated on Bob’s local machine

Make file changesStage ChangesCommit Changes

git add filenamegit commit -m ‘…’ vi filename

1) git push

Page 23: Git101

Pull commits from remote repo

• cd my_project

• git pull origin masterOR

• git pull

Page 24: Git101

Lab with remote repos(on Github.com)

User A

• Modify file locally

• Add/Stage that file to the commit

• Commit your changes

• Push those changes to GitHub

User B

• Pull those changes from GitHub