Terminal and Git 101

A primer for
productive web development

Made with ♥ by VCUarts
Contributers: Mark Luetke & Cody Whitby

Terminal

What is a terminal?

A terminal is an interface for typing text based commands.

Why use a terminal?

Efficiency, Efficiency, Efficiency.

Most modern professional web development tools are command line based. Not knowing even the most basic terminal commands is a serious handicap.

It's not hard.

But won't the universe implode if I screw up a command???

Everything is going to be fine.

Prerequisites

X-Code must be installed. Available for free in the App Store.

Basic commands



$ cd
$ ls
$ mkdir
$ touch
$ open

cd

Change directory


#change to root directory
$ cd ~ 

#change to myproject directory
$ cd github/projects/myproject 

#move back a single directory
$ cd ..

#move back three directories
$ cd ../../../
Tip: use TAB to autocomplete

ls

List directory contents


$ ls 

aDirectory        anotherFile.txt         aPic.jpg 
myFile.txt        file.txt      

mkdir

create a new directory


#create mydirectory within the current directory 
$ mkdir mydirectory

touch

create a new file


#create mynewfile.txt within the current directory 
$ mkdir touch mynewfile.txt 

open

open a file or directory


#open the current directory in finder
$ open .

#open textfile.txt with it's the default program
$ open textfile.txt 

#open textfile.txt with pages
$ open -a pages textfile.txt 

Further Study

Terminal Cheatsheet for Mac ( basics )

There are many more commands that exist, so many that it is possible to work exclusively from the command line.

Like many things in web development, this is yet another very deep rabbit hole...

Git

What is Git

Git is an open source program for tracking changes in files

Why should I use Git?

Git saves the entire history of a project allowing you to restore to any point. It pretty much makes efficient collaborative programming possible and you WILL need to understand it if you do any sort of professional development work with a team.

Why should I use Git in the terminal instead of an app?

Efficiency, Efficiency, Efficiency. Professional developers live in their terminal and the command line is the native implementation of Git.

Basic Git Commands



$ git init
$ git status
$ git add
$ git commit
$ git fetch
$ git pull
$ git push

init

creates a .git directory



$ git init

status

displays the status of our repo, any changes, new files, deleted files, etc.



$ git status

add

tell git to track new files



$ git add filename.txt
$ git add .

commit

take a snapshot of changes and new files



$ git commit
$ git commit -m "message describing the changes"

fetch

check a remote repo for changes



$ git fetch

pull

pull down any changes from a remote and apply them to the local project



$ git pull

push

add any commits to the remote repo



$ git push

Using Git in a Existing Project



$ git init



$ git add .
$ git commit -m "initial project commit"

Pushing a Repo to GitHub

First you must create a new project on GitHub



$ git remote add origin http://yournewprojecturl.com/something.git
$ git push origin master

Pushing changes to GitHub

After making changes to a project



$ git status
$ git add .
$ git commit -m "message about what we changed"
$ git push

Cloning a Existing Project

Pull down a project to use locally



$ cd directory/you/want
$ git clone https://github.com/user/project.git

# or clone into a folder with a different name
$ git clone https://github.com/user/project.git new-folder

Futher Study

try.github.io

Learn Git Branching

git flight rules

Thanks!

Made with ♥ by VCUarts
Contributers: Mark Luetke & Cody Whitby