Getting Started with GIT. Basic Navigation cd means change directory cd.. moves you up a level cd...

30
Getting Started with GIT

Transcript of Getting Started with GIT. Basic Navigation cd means change directory cd.. moves you up a level cd...

Page 1: Getting Started with GIT. Basic Navigation cd means change directory cd.. moves you up a level cd dir_name moves you to the folder named dir_name A dot.

Getting Started with GIT

Page 2: Getting Started with GIT. Basic Navigation cd means change directory cd.. moves you up a level cd dir_name moves you to the folder named dir_name A dot.

Basic Navigation

• cd means change directory• cd .. moves you up a level• cd dir_name moves you to the folder named

dir_name• A dot (.) refers to the current directory• ls displays directory contents

Page 3: Getting Started with GIT. Basic Navigation cd means change directory cd.. moves you up a level cd dir_name moves you to the folder named dir_name A dot.

Create a Project from Scratch

git init project creates a project directorygit add adds files to the directorygit commit –m"message" commits the changes

$ cd projects$ git init project1

*** create file1.txt ***

$ cd project1$ git add file1.txt$ git commit -m "Committing project 1"

Create a projects directory on ned in 216

Page 4: Getting Started with GIT. Basic Navigation cd means change directory cd.. moves you up a level cd dir_name moves you to the folder named dir_name A dot.

Create a Project from an Existing Directory

git init . initializes the current directorygit add * adds all files in the directorygit commit –m"message" commits the changes

$ cd ../projects/project2$ git init .$ git add *$ git commit -m "Committing project 2"

Create a projects/project2 directory, and create a file in that directory called file2.txt

Page 5: Getting Started with GIT. Basic Navigation cd means change directory cd.. moves you up a level cd dir_name moves you to the folder named dir_name A dot.

View your Commit Logs

git log displays your log history

Page 6: Getting Started with GIT. Basic Navigation cd means change directory cd.. moves you up a level cd dir_name moves you to the folder named dir_name A dot.

Check your Status

git status displays the status of the repoIn the projects/project2 directory, modify file2.txt and create a file called file3.txt

modified file

new file

Page 7: Getting Started with GIT. Basic Navigation cd means change directory cd.. moves you up a level cd dir_name moves you to the folder named dir_name A dot.

Update your repo

add the file

commit the changes

check the status

Page 8: Getting Started with GIT. Basic Navigation cd means change directory cd.. moves you up a level cd dir_name moves you to the folder named dir_name A dot.

Try It

• Navigate to the projects directory• Initialize project3• Create file4.txt in the directory

– Add file4 to the repo– View Git status– Commit the change

• Modify file4– View Git status– Commit the change

• Create file5.txt in project3– View Git status– Add it to the repo– Commit the change

Page 9: Getting Started with GIT. Basic Navigation cd means change directory cd.. moves you up a level cd dir_name moves you to the folder named dir_name A dot.

Access a Git Project from GitHub

• Most open source projects have a read-only Git URL• Visit github.com Explore• git clone https://... copies repository content to your

system

Page 10: Getting Started with GIT. Basic Navigation cd means change directory cd.. moves you up a level cd dir_name moves you to the folder named dir_name A dot.

Access a Git project

URL -- https://github.com/garrick/git-for-one-presentation.git

Create a new folder from the command line

Change to the new folder

Pull down a copy of a github project

Display directory contents

Right click here to Edit Paste,

or press the Insert key on the keyboard

Page 11: Getting Started with GIT. Basic Navigation cd means change directory cd.. moves you up a level cd dir_name moves you to the folder named dir_name A dot.

Keep Current

• git pull will bring down latest content• If you've made conflicting changes, this may

not work easily• You can always delete the directory contents

and pull down a fresh copy

Page 12: Getting Started with GIT. Basic Navigation cd means change directory cd.. moves you up a level cd dir_name moves you to the folder named dir_name A dot.
Page 13: Getting Started with GIT. Basic Navigation cd means change directory cd.. moves you up a level cd dir_name moves you to the folder named dir_name A dot.

Sharing on GitHub

Create a GitHub account

Page 14: Getting Started with GIT. Basic Navigation cd means change directory cd.. moves you up a level cd dir_name moves you to the folder named dir_name A dot.

Pick a Plan

With a free account, all repos are public.

Page 15: Getting Started with GIT. Basic Navigation cd means change directory cd.. moves you up a level cd dir_name moves you to the folder named dir_name A dot.

Create a Repository on GitHub

Page 16: Getting Started with GIT. Basic Navigation cd means change directory cd.. moves you up a level cd dir_name moves you to the folder named dir_name A dot.

Set up the Repository

Page 17: Getting Started with GIT. Basic Navigation cd means change directory cd.. moves you up a level cd dir_name moves you to the folder named dir_name A dot.

Set up your GitHub "origin"

Copy the URL from GitHub

In Bash: $git remote add origin https://...Paste URL

You can paste by right clicking

Page 18: Getting Started with GIT. Basic Navigation cd means change directory cd.. moves you up a level cd dir_name moves you to the folder named dir_name A dot.

Push to GitHub$git push -u origin master

Copies your project to GitHub

Enter your credentialsYou should only have to do this once!

"Origin" is GitHub

"Master" is local copy

Page 19: Getting Started with GIT. Basic Navigation cd means change directory cd.. moves you up a level cd dir_name moves you to the folder named dir_name A dot.

Voila!

Page 20: Getting Started with GIT. Basic Navigation cd means change directory cd.. moves you up a level cd dir_name moves you to the folder named dir_name A dot.

Add a ReadMe

Page 21: Getting Started with GIT. Basic Navigation cd means change directory cd.. moves you up a level cd dir_name moves you to the folder named dir_name A dot.

Pull the ReadMe into your Local copy

Copy URL from GitHub

In Bash: $ git pull URL

Page 22: Getting Started with GIT. Basic Navigation cd means change directory cd.. moves you up a level cd dir_name moves you to the folder named dir_name A dot.

Try It

• Create a GitHub repo for Project1• Push your local copy to the repo• Add a ReadMe file in GitHub• Pull the ReadMe to your local copy• Modify file1.txt in Project1• Add a new file to Project1• Commit your changes (don't forget to add the new

file to the repo first!)• Push your changes to GitHub

Page 23: Getting Started with GIT. Basic Navigation cd means change directory cd.. moves you up a level cd dir_name moves you to the folder named dir_name A dot.

Deleting a Repo from GitHub

• Select the Repository• Click Settings• Click "Delete this repository "under Danger

Zone– This cannot be undone!

• Type the name of the repository to confirm

Page 25: Getting Started with GIT. Basic Navigation cd means change directory cd.. moves you up a level cd dir_name moves you to the folder named dir_name A dot.

Open Git Bash

Page 26: Getting Started with GIT. Basic Navigation cd means change directory cd.. moves you up a level cd dir_name moves you to the folder named dir_name A dot.

Configure Git

Configure usernameConfigure password

Everything elseis just the same!

This creates two key-value pairs, used for tracking commits.

$ git config --global user.name "Joe Shmo"$ git config --global user.email "[email protected]"

Page 27: Getting Started with GIT. Basic Navigation cd means change directory cd.. moves you up a level cd dir_name moves you to the folder named dir_name A dot.

Store your Credentials

• Download Windows Credential Store for Git• Run It!• Click Yes

Page 28: Getting Started with GIT. Basic Navigation cd means change directory cd.. moves you up a level cd dir_name moves you to the folder named dir_name A dot.

Summary• Check status

• git status• Add a remote location to

upload files• git remote add origin url

• Push changes from local to remote• git push -u origin master

• Pull changes from remote to local• git pull url

• Initialize a project• git init projectName• git init .

• Add a file• git add fileName• git add *

• Commit changes• git commit -m "remark"

• View the log• git log

Page 29: Getting Started with GIT. Basic Navigation cd means change directory cd.. moves you up a level cd dir_name moves you to the folder named dir_name A dot.

Git Isn't Just for Code

• You can commit anything to a Git repository– Pictures– Word docs– PowerPoint presentations– Videos– Music– etc.