1 of 23

Big Ideas in Software Engineering & Intro to Version Control

Fall 2024

2 of 23

Intro to git

  • What is git?
  • What experience do you have using git (if any)?
  • Good Reference: https://git-scm.com/book/en/v2

3 of 23

Today: Local Workflow

4 of 23

Intro to git

  • What is git?
  • What experience do you have using git (if any)?
  • Good Reference: https://git-scm.com/book/en/v2

5 of 23

Git v. GitHub

  • What is git?
    • Git is a free and open source version control system
  • What is GitHub?
    • GitHub is a company that provides cloud-based hosting services for managing your git repositories.
  • What are some of the services GitHub provides?
    • Issue trackers, third-party integrations (e.g., CI/CD tools), website hosting, branch protection, tools for managing teams and organizations, tools / notifications to identify security issues (i.e., problematic node / python dependencies, accidentally checking in passwords and API keys, and more)

5

6 of 23

How to Learn Git

The best way to learn git is to practice using git while working on a collaborative software project (like this class)!

There are also many great references you can draw from, including:

  • The Git SCM Book (SCM stands for source code management)
  • Video tutorials (e.g., Google “youtube rebase” or “google revert”)
  • Conceptual diagrams (Google them) – which explain how various commands / workflows work (like today’s assigned video).

6

7 of 23

Simple Git Workflow: Solo Project (Today)

  1. Clone an existing GitHub repository
  2. Edit / update / delete some files
  3. Stage your changes to git
  4. Commit your changes to git
  5. Push (upload) your changes back to the original repository.

7

8 of 23

Solo Project Workflow (Simple)

8

Scenario: you want to make changes to a code repository that

lives on another computer / server (e.g., on GitHub)

9 of 23

Solo Project Workflow (Simple)

9

First, issue the git clone command. This downloads the code files (left) as well as a hidden .git folder of tracking files (middle), to your working directory (pwd)

10 of 23

Solo Project Workflow (Simple)

10

Note: In addition to the local repo, git has a concept of a “staging area.” �Files are ignored by git until they are staged.

11 of 23

Solo Project Workflow (Simple)

11

Use the git status command to tell you which of your files have been changed since the last commit (the current version of your codebase).

12 of 23

Solo Project Workflow (Simple)

12

To stage your changes (tell git which files you want to commit), use the git add command. You can add individual files (by path), or all changed files (use dot).

13 of 23

Solo Project Workflow (Simple)

13

When you’re ready to commit your changes (add them to the codebase), use the git commit command. All commits require a message describing the commit.

14 of 23

Solo Project Workflow (Simple)

14

Note that the added files are no longer highlighted, as they are now part of the code repository (changes are stored within the .git system files)

15 of 23

Solo Project Workflow (Simple)

15

To publish your changes back to the shared codebase (remote server), �use the git push command.

16 of 23

Simple Git Workflow: Solo Project Commands

16

clone

Copies a remote repository (e.g., one hosted on a GitHub server) onto your local machine (within your current directory).

status

Tells you which of the files in your current directory are different from the latest commit in the repo.

add

Stages the specified files to be committed

log

Shows you the commit history

commit

Saves a snapshot of your staged files at the moment the commit is issued. Each commit represents the state of your code at a particular moment in time.

push

Uploads your commits to a remote repo

pull

Downloads changes from a remote repo to your local repo

17 of 23

Common Mistakes People Make

17

18 of 23

1. Avoid nested git repos

csci338

└── class-exercises-fall2024

├── .git

├── .gitignore

├── README.md

└── app

├── .git

├── .gitignore

├── README.md

└── src

18

BAD: reps are nested (app is a child of class-exercises-fall2024).

Should class-exercises-fall2024 also be tracking the code in app?

19 of 23

1. Side by Side Repos OK!

csci338

├── app

│ ├── .git

│ ├── .gitignore

│ ├── README.md

│ └── src

└── class-exercises-fall2024

├── .git

├── .gitignore

└── README.md

19

OK: Separate repos are not nested (in sibling directories)

20 of 23

2. Don’t forget to add a commit message

If you issue the git commit command without a commit message, it may open a vim editor and ask you to add your commit message via vim.

If this happens, you can either:

  1. Add a message to the top of the text file using the vim commands we practiced on Tuesday.
  2. Exit vim (press Escape Key and then :q!) and try again with a message:
    • git commit -m 'Thoughtful commit message'

20

21 of 23

3. Don’t check in API keys, passwords, or dependencies

Use the .gitignore file to exclude files you don’t want under version control.

Files you typically want to exclude from version control:

  • Third party modules / packages
  • Protected information (e.g., passwords, API keys, etc.),
  • Personal config files (e.g., .vscode settings file)
  • System files (e.g., .DS_Store, etc.) that aren’t part of the shared codebase.
  • Compiled files (e.g., *.pyc, *.class files)
  • Virtual environment files

21

22 of 23

Outline

  1. Discussion of the Readings
  2. Git v. GitHub
  3. Git Concepts
  4. Lab 2

22

23 of 23