1 of 23

CSE 163

Intro to Git�

Arpan Kapoor�

2 of 23

Announcements

  • Checkpoint 5 due tonight

  • Project & Portfolio Report/Code due tonight

  • Last day to submit the Course Evaluation if you want the Bonus Resubmission period!
    • Any ONE Creative Component + any ONE Technical Component!

  • Add presentation slides to your section folders by 11:59pm Wednesday!

2

3 of 23

Who am I?

  • Arpan (arr-pin) akap1204@uw.edu
  • BS/MS student in the ECE department
  • TA in the Allen School for six quarters (primarily 163)
  • Primary education interests include computer architecture and teaching computer science!

3

4 of 23

Version Control

What are its benefits and why do we use it?

  • Allows for collaboration
  • Revert mistakes easily
  • Accountability

4

5 of 23

What is Git?

5

  • Created by Linus Torvalds in 2005
  • Desired an efficient version control system that supported large scale coding projects
    • couldn’t find one, so he made it!
  • Centralized vs. distributed version control:
    • Centralized: a central server processes, maintains, and shares all changes.
    • Distributed: all users maintain a working copy (a local repository) on their own machine.

6 of 23

Git vs. GitHub, GitLab, etc.

6

  • Git is the tool that allows this version control system to function locally.

  • GitHub and Gitlab are hosting services for git’s remote functionalities (hosting remote repositories).

7 of 23

Repositories

  • A repository, commonly referred to as a repo is a location that stores a copy of all files.
  • Can be either local, or remote (online, non-local)
  • What should be inside of a repository?
    • Source code files (i.e. .py files, .ipynb files, etc)
    • Images, general resources files
    • README.md files and notes
  • What should not be inside of a repository (generally)
    • Executables or generated files
    • Data (i.e. .csv files, .shp files, etc.) or files that take up a lot of space

7

8 of 23

Repositories

  • With git, everyone working on the project has a complete version of the repository.
    • There is a remote repository, which is the central repository
    • Remote repositories are hosted on services like GitHub or Gitlab
    • Everyone has a local copy of the repository, which is what we use to send our own changes to the remote repository.

8

Developer 1

Developer 2

Remote Repository

Push/Pull Changes

9 of 23

9

The 4 Stages of Git

Working Directory

Working changes in your development environment

Staging Area

Changes you’re preparing to commit

Local Repository

Local copy of the repository with your committed changes

git stage

git commit

Remote Repository

Remote shared repository on Github, Gitlab, etc.

10 of 23

Git Commands

  • status
  • add
  • commit

Usage: git status

  • Shows info about current status of your working directory and staging area
  • Indicates the following:
    • uncommitted changes in working directory
    • committed changes in the staging area
    • new, untracked files
    • branch information
    • any relevant conflicts

10

11 of 23

Git Commands

  • status
  • add
  • commit

Usage: git add <file1> <file2> ...

  • Moves files from your working directory to the staging area
  • Can be used to add multiple files in one go, or just one at a time
  • Also accepts the relative path of a file if not currently within the file’s directory

11

12 of 23

Git Commands

  • status
  • add
  • commit

Usage: git commit -m “commit msg”

  • Moves files from the staging area to your local repository by packaging them as commits
  • “-m” flag indicates the inclusion of a single-line commit message within the command
  • Alternatively, use “git commit” to open a text editor to write longer commit messages
  • Best practice is to commit frequently!

12

13 of 23

13

The 4 Stages of Git

Working Directory

Staging Area

Local Repository

Working changes in your development environment

Changes you’re preparing to commit

Local copy of the repository with your committed changes

Remote Repository

Remote shared repository on Github, Gitlab, etc.

git stage

git commit

git push

git pull

14 of 23

More Git Commands

  • clone
  • push
  • pull

Usage: git clone <URL>

  • Used to clone an already existing remote repository onto your local machine
  • For private repositories, requires authentication (i.e. via SSH keys, etc.)
  • After cloning, you can collaborate with others who have access to the remote repository!

14

15 of 23

More Git Commands

  • clone
  • push
  • pull

Usage: git push

  • Used to push changes from your local repository to the remote repository
  • Once you push your changes, they are visible for all others to see!

15

16 of 23

More Git Commands

  • clone
  • push
  • pull

Usage: git pull

  • Used to update your working directory with changes from the remote repository
  • Combination of the commands “fetch” and “merge”
    • Fetch retrieves the changes from the remote repository to your local repository
    • Merge combines the changes in your local repository with your working directory

16

17 of 23

17

Branching and Diverging Branches

A

B

C

D

E

NOTE: The pointer from one commit to another points to the previous commit, so the arrows go back in time. ‘A’ is the first commit, and ‘E’ is the most recent commit.

This visualization illustrates two scenarios:

  • A developer working on their own branch �(with commit “D”) separate from branch “main”
  • A developer trying to pull changes, but encountering a diverging branch due to conflicting changes from the remote repo

18 of 23

“Undo” Git Commands

  • reset
  • revert

Usage: git reset HEAD filename

  • Used to remove a file previously added to the staging area
  • Does not affect changes in your working directory

18

19 of 23

“Undo” Git Commands

  • reset
  • revert

Usage: git revert HEAD

  • Deleting a commit involves altering the entire commit history and can cause issues
  • While it is possible to “delete” commits, it’s best practice to avoid doing so
    • think carefully about committing
    • instead, revert the commit!

19

20 of 23

Discuss!

Now that we have a basic understanding of Git, how does it compare to other version control systems you’ve used like Docs, Slides?

  • What are each’s pros and cons?
  • What kind of task/work is more suitable for each?
  • Do you think you will start using Git? Do you find it useful?

20

21 of 23

21

Demo!

22 of 23

Before Next Time

  • Complete Lesson 25 in Canvas
  • Turn in Checkpoint 5
  • Turn in Report/Code

Next Time

  • Ed poll for special topics!

22

23 of 23

Extra Resources

  • CSE 391
    • “Introduction to tools commonly used in software development. Topics include using a command-line interface, writing scripts for file and string manipulation, managing user permissions, manipulating text with regular expressions, using build-management tools, and using version-control systems.”

23