CSE 391
Introduction to git
Slides created by Josh Ervin and Hunter Schafer. �Based off slides made by Marty Stepp, Jessica Miller, Ruth Anderson, Brett Wortzman, and Zorah Fung
AGENDA
ADMINISTRIVIA
AGENDA
OPEN–SOURCE – AN INTERLUDE
Interested in more? Definitely come to Matt’s office hours :)
FUN HW3 P5 ANSWERS
# How many people that prefer cats are in CSE 351 in autumn 2023?
cat intro_survey_23au.csv | grep "Cats" | cut -d, -f4 | grep "Yes" | wc -l
�# How many students chose chocolate, but did not choose cats.
grep -i "chocolate" combined_results.csv | grep -iv "cats" | wc -l
�# Is there someone else besides me whose response in the combined_results.csv says
# Twix, steak, and Cats case-insensitively? If the following command produces
# a value that is greater than 1, then the answer is yes.
grep -i "Twix" combined_results.csv | grep -i "steak" | grep "Cats" | wc -l
FUN HW3 P5 ANSWERS
# What is the most common favorite dinner among students who prefer dogs as pets?
grep -i 'Dogs' intro_survey_23sp.csv | cut -d ',' -f 2 | grep -v 'Favorite Dinner' | sort | uniq -c | sort -nr | head -n 1 | awk '{print $2, $1}'
# How many preferred candies were only listed once in the surveys?
cut combined_results.csv -d, -f1 | sort -f | uniq -ic | grep " 1 " | wc -l
DISCUSSION QUESTION #1
What are the four different phases of git that we’ve learned? ��What commands do you know to move changes from one phase to the next? ��Is there ever more than one way to move a change from one phase to another?
DISCUSSION QUESTION #7
One popular “version control” that you’ve probably used is Google Drive/Docs. How is this similar to git? How is it different?
DISCUSSION QUESTION #8
Using the man page, how would you undo (or revert) a commit. Is this what you expected? Why?
AGENDA (FROM VIDEO)
ROADMAP
VERSION CONTROL - INDIVIDUAL
VERSION CONTROL - TEAMS
VERSION CONTROL
REPOSITORY
REPOSITORY
Developer 1
Developer 2
Developer 3
Push/Pull Changes
GIT: FOUR PHASES
Working Directory
Staging Area/Index
Local Repository
Remote Repository
Working changes
Changes you’re preparing to commit
Local copy of the repository with your committed changes
Remote shared repository (Usually stored with a platform like GitHub/Gitlab)
git stage
git commit
git push
NOTE: There are way more git commands than what is listed here - this is a simplified model to get us started.
INSPECTING A REPOSITORY
git status
git log
Working directory
Staging Area
Commit History
Suppose a run of git status show the following:
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: file1.txt
modified: file2.txt
Based on this information, at what location are the changes to file1.txt and file2.txt within the git phases on the previous slides.
Suppose a run of git status show the following:
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: file1.txt
modified: file2.txt
We want to run a sequence of commands that includes the changes to file1.txt in a single commit followed by the changes to file2.txt in another commit in the local repository. What commands should we run?
GIT COMMANDS
git clone url [dir] | Copy a git repository |
git add files | Adds file contents to staging area |
git stage files | Same as git add files |
git commit | Takes a snapshot of staging area and creates a commit |
git status | View status of files in working directory and staging area |
git diff | Show difference between staging area and working directory |
git log | Show commit history |
git pull | Fetch from remote repository and try to merge |
git push | Push local repository to remove repository |
ADDING AND COMMITTING FILES
COMMIT MESSAGES
GIT: FOUR PHASES WITH REMOTE
Working Directory
Staging Area/Index
Local Repository
Remote Repository
git stage ...
git commit
git push
git pull
CSE GITLAB
For a brief introduction to SSH keys, see Ed (but ignore part about attu).
All credit to previous 391 Instructors for this slide, including Marty Stepp, Brett Wortzman, Jessica Miller, and Ruth Anderson
Get Ready to Use Git
All credit to previous 391 Instructors for this slide, including Marty Stepp, Brett Wortzman, Jessica Miller, and Ruth Anderson