Version Control Review

Version Control - Definition

What’s version control?

Version control software allows you to record changes to a file or set of files over time. With version control, you can:

Motivation

Why would we use version control? (besides being required for this course!) →

Tools

What version control software are we using?

Some Potential Confusion

What’s the difference between git and github

More Definitions…

Define the following terms: repository, local repository, remote repository, git and github

And Even More Definitions….

Define the following terms: commit and diff

Where Are My Files

In your local repository, git stores your files and versions of your files in a few different conceptual places:

Two Basic Workflows

  1. Creating and setting up local and remote repositories
  2. Making, saving, and sharing changes

Creating Repositories

Making, Saving, and Sharing Changes

Github Will Serve as our Remote Repository

ALL ASSIGNMENTS ARE REQUIRED TO BE SUBMITTED VIA COMMAND LINE!

git

Commands for Setting Up Local Repositories…

How do you create a local repository?

git init

How do you configure your local repository with your name and email address?

git config user.name "your name"
git config user.email "your@email.address"

Commands for Setting Up Remote Repositories…

How do you create a remote repository?

# for github, you can use curl!
# replace 'your github username' with your username
# replace 'your repository name' with the name you'd like to call your repository
# keep EVERYTHING ELSE as is
curl -u 'your github username' https://api.github.com/user/repos -d '{"name":"your repository name"}'

How do you link your local and remote repository?

# replace "your username" and "the url to your repository" appropriately 
# (keep the @ symbol... it means... your user, at that web site)
git remote add origin https://github.com/your github user name/your_repository.git

Summary for Setting Up and Linking Remote and Local Repositories

git init
git config user.name  "your user name"
git config user.email "your@email.address"
curl -u 'your github user name' https://api.github.com/user/repos -d '{"name":"your repository name"}'
git remote add origin https://github.com/your github user name/your_repository.git

Working With Your Files

What’s the typical workflow for changing and saving your files using version control?

  1. make changes
  2. git diff –color (show your changes)
  3. git status (to see the status of your changes)
  4. git add –all (to stage your changes for committing)
  5. git status (to see your staged changes)
  6. git commit -m ‘my message’ (to save your changes)
  7. git log –color (show your changes so far)
  8. git push origin master (optionally send/share your changes to a remote repository)

git status

What does git status do?

git status - show what changes are ready to be committed as well as changes that you are working on in your working directory that haven’t been staged yet

git add

What does git add do?

# it marks a file or files as ready to be saved

# add all
git add --all 

# add specific file
git add myfile.txt

git commit

What does git commit do?

# git commit takes a snapshot of your work
# (it saves it!)

# in the directory of your repository
# don't forget the commit message
git commit -m "commit message goes here"

git log

What does git log do?

# git log shows you the commit history of your repository or file
git log

# you can also colorize the output:
git log --color

git diff

What does git diff do?

# it shows the line-by-line differences between your last commit and your working directory

# use --color for syntax highlighting
git diff --color

Summary for Working With Files

# make changes
# look at the differences between your last save and your current changes
git diff --color

# check on the status of your changes
git status

# "stage" or mark your changes as ready to be saved
git add --all

# check the status again to see that you changes are ready to be saved
git status

# save!
git commit -m "my message"

# show a log of your changes so far
git log --color (show your changes so far)

# send to a remote repository (to submit an assignment)
git push origin master 

All git commands must be run in your repository directory (where you ran git init)

Lab 5, Part 1