Today we will learn to work with git repositories offline, this requires understanding some about file systems and how content is organized on computers.
We will learn:
relative and absolute paths
basic bash commands for navigating the file system
authenticating to GitHub on a terminal
how to clone a repo
how fetch and checkout work
Let’s get organized¶
For class you will need to have a folder on your computer where you will keep all of your materials.
We will start using the terminal today, by getting all set up.
Open a terminal window. I am going to use bash commands
If you are on MacOs, your default shell is zsh which is mostly the same as bash for casual use. You can switch to bash to make your output more like mine using the command bash if you want, but it is not required.
if you are on windows, your GitBash terminal will be the least setup work to use bash
if you have WSL (if you do not, no need to worry) you should be able to set your linux shell to bash
The prompt is the part in the terminal at the current line before you can type, mine is
brownsarahm@~ $
In the notes, I remove my prompt from the excerpts, this makes it so that you can copy the blocks to use them if you are practicing, stuck, or making up and need help to get around a typo
When ever we are in the terminal, we always have to be in a particular location within the file system, because the computer is organized as a collection of files.
The command pwd print working directory
also known as the current path
pwdMy path is:
/Users/brownsarahmIt outputs the absolute path of the location that I was at.
we start at home (~)
this symbol (~) is called the “tilde” pronounced till-dah
Make a plan¶
What you want to have is a folder for class (mine is systems) in a place you can find it (mine is in my inclass folder`).
You will need a place where you can download multiple repositories and you will need to know the relative path from one to another, so having them “close” to one another is helpful.
You might:
make a CSC311 folder in your Documents folder and an inclass folder in there
make an inclass folder in the CSC311 folder you already made
use the CSC311 folder as your in class working space
do you know where you will put your work?
(you can either write down your planned path or say yes)
executing the plan¶
To act on this plan, we need a few new commands, first to get to the place where we want the folder, then to make the folder.
We can change directory with cd
We can mak a new directory with mkdir
When you have your folder, print the path and send it here:
Create a folder that you will use for class that meets the above criteria and move into it
Solution to Exercise 1
Use cd to move to where you want the folder, then use mkdir to create it, then cd to get there.
Your exact location will be different than mine.
I will work inside my documents folder, inside a folder called inclass.
cd Documents/inclass/use tab to complete things, for example I typed cd Doc + tab + inc + tab to execute the cell above
and make a folder for this class there, called systems
mkdir systemsif you use mkdir without an input, called an argument....
mkdirit tells you how you are supposed to use it instead of doing anything
usage: mkdir [-pv] [-m mode] directory_name ...usagetells us what this line is sayingmkdirnext says that the command should start the linethe
[]tell us the next few things are not required, they are called optionsdirectory_nameis a required input, or argumentthe
...says that we can pass more than onedirectory_nameto create multiple folders at the same time
Once we make folde we can move into it:
cd systems/and see the path
pwd/Users/brownsarahm/Documents/inclass/systemsif we use cd without a path, it goes back to home
cdit does not have output, but we can see the prompt update
or verify with pwd:
pwd/Users/brownsarahmWe can go back by providing the whole relative path to where we want to go. It is relative because it does not start from the top of the tree, but instead is how to get there from where we are.
cd Documents/inclass/systems/we can see it is relative because it does not start with /
pwd/Users/brownsarahm/Documents/inclass/systems/Users/brownsarahm/Documents/repos/compsys-progtools/lesson-plans/manually_edited/03-gitoffline.md
pwd/Users/brownsarahm/Documents/inclassRelative paths can also combine multiple ... For example
cd ../../Finally, we’ll go back to the folder that we will use for the course
cd Documents/inclass/systems/A toy repo for in class¶
this repo will be for in class work, you will not get feedback inside of it, unless you ask, but you will answer questions in your kwl repo about what we do in this repo sometimes
only work in this repo during class time or making up class, unless specifically instructed to
Go to prismia and find the accept the assignment link
Getting code from GitHub¶
We have two choices to Download a repository:
clone to maintain a link using git
download zip to not have to use git, but have no link
we want option 1 beacuse we are learning git
Depending on what terminal you are doing you have to do the steps of authenticate and start cloning in different orders, this first time while we configure your GitHub account on your computer.
GitBash (windows mostly)¶
git cloneand paste your URL from GitHubthen follow the prompts, choosing to authenticate in Browser.
Native terminal ( MacOS X/Linux/WSL)¶
enter
gh auth loginand follow the prompts.then
git cloneand paste your URL from github
If nothing else works¶
Create a personal access token. This is a special one time password that you can use like a password, but it is limited in scope and will expire (as long as you choose settings well).
Then proceed to the clone step. You may need to configure an identity later with git config
also go to office hours later to get better authentication
Cloning a repository¶
We will create a local copy by cloning
git clone https://github.com/compsys-progtools/gh-inclass-sp26-brownsarahm.gitCloning into 'gh-inclass-sp26-brownsarahm'...
remote: Enumerating objects: 13, done.
remote: Counting objects: 100% (13/13), done.
remote: Compressing objects: 100% (8/8), done.
Receiving objects: 100% (13/13), 4.43 KiB | 4.43 MiB/s, done.
remote: Total 13 (delta 0), reused 4 (delta 0), pack-reused 0 (from 0)Confirm it worked with one more new command ls which is short for list.
lsgh-inclass-sp26-brownsarahmWe see the new folder that matches our repo name
We can enter that folder
cd gh-inclass-sp26-brownsarahm/When we compare the local directory to GitHub
lsREADME.mdNotice that the .github/workflows that we see on GitHub is missing,
that is because it is hidden. All file names that start with . are hidden.
We can actually see the rest with the -a for option. Options are how we can pass non required parameters to command line programs.
ls -a. .git README.md
.. .githubWe also see some special “files”, . the current location and .. up one directory
Where else in programming have you seen something like a flag?
Hint
Think about a command line program or command like a function
Solution to Exercise 2
In some programming languages, like Python, positional arguments are very similar to these
We can use tab to complete once we have a unique set of characters. If what we have is not unique bash will do nothing when you press tab once, but if you press it multiple times it will show you the options:
ls .git.git/ .github/then if i press h and tab again it completes:
ls .github/workflowsHow do I know what git knows?¶
git status is your friend.
git statusOn branch main
Your branch is up to date with 'origin/main'.
nothing to commit, working tree cleanls -a. .git README.md
.. .githubgit statusOn branch main
Your branch is up to date with 'origin/main'.
nothing to commit, working tree cleanthis command compares your working directory (what you can see with ls -a and all subfolders except the .git directorty) to the current state of your .git directory.
Making a branch with GitHub and working offline¶
Run the one action in your this repo. It will create 3 issues for you.
First the about issue, create a branch using the link in the development section of the right side panel. See the github docs for how to do that.
Then it gives you two steps to do. We are going to do them one at a time so we can see better what they each do.
First we will update the .git directory without changing the working directory using git fetch. We have to tell git fetch where to get the data from, we do that using a name of a remote.
git fetch originFrom https://github.com/compsys-progtools/gh-inclass-sp26-brownsarahm
* [new branch] 2-create-an-about-file -> origin/2-create-an-about-fileWe can look at the repo to see what has changed.
git statusOn branch main
Your branch is up to date with 'origin/main'.
nothing to commit, working tree cleanThis says nothing, because remember git status tells us the relationship between our working directory and the .git repo.
ls -a. .git README.md
.. .githubNext, we switch to that branch.
git checkout 2-create-an-about-filebranch '2-create-an-about-file' set up to track 'origin/2-create-an-about-file'.
Switched to a new branch '2-create-an-about-file'git statusOn branch 2-create-an-about-file
Your branch is up to date with 'origin/2-create-an-about-file'.Creating a file on the terminal¶
The touch command creates an empty file.
touch about.mdWe can use ls to see our working directory now.
lsabout.md README.mdwe can also check with git.
git statusOn branch 2-create-an-about-file
Your branch is up to date with 'origin/2-create-an-about-file'.
Untracked files:
(use "git add <file>..." to include in what will be committed)
about.md
nothing added to commit but untracked files present (use "git add" to track)it says the file is untracked meaning that git status saw the file exists, but there is no previous version of it inside the .git folder
Making a commit locally¶
we want to track the file, so we need to commit it.
Commiting locally requires two steps:
stage the file(s) to include in the commit, which is a snapshot of the directory at this point in time
create the commit (take the snapshot)
the two step process allows us to, for example edit several files and then only commit changes to some of them, or make separate commits for different edits.
A lot of the time, we want to stage everything. We can use the . which is a special file for the current location to do that.
we use git add to add files to the staging area.
git add .it has no output, but git status will let us see what changed.
git statusOn branch 2-create-an-about-file
Your branch is up to date with 'origin/2-create-an-about-file'.
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: about.mdNow the files are staged “to be committed”
Notice that each time, git status has a hint about what you might want to do next or to undo what you just did
Notice that now the file is to be comitted intead of untracked
a commit message is required if you do not type on and run git commit it will open vim or vi. To get out of those programs, use esc to get into command mode then type :wq for write and quit
We will make a commit using the -m option to add the message directly.
git commit -m 'create empty about'[2-create-an-about-file a254c24] create empty about
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 about.mdand finally check status
git statusOn branch 2-create-an-about-file
Your branch is ahead of 'origin/2-create-an-about-file' by 1 commit.
(use "git push" to publish your local commits)
nothing to commit, working tree cleanMany of you got a warning about git credentials.
We will fix that in lab on Monday, no need to worry.
Summary¶
Another way to think abut things (and adds some additional examples to help you differentiate between categories and examples of categories)
Today’s bash commands:
command | explanation |
|---|---|
| print working directory |
| change directory to path |
| make a directory called name |
| list, show the files |
| create an empty file |
We also learned some git commands
command | explanation |
|---|---|
| describe what relationship between the working directory and git |
| make a new folder locally and download the repo into it from url, set up a remote to url |
| add file to staging area |
| commit using the message in quotes |
| send to the remote |
Prepare for Next Class¶
Find the glossary page for the course website, link to it in a comment.
Review the terms for the next class: shell, terminal, bash, git, zsh, powershell, GitHub. Make a diagram using mermaid to highlight how these terms relate to one another. Put this in a file called
terminal-vocab.mdon a branch linked to this issue. You might like to work with mermaid.live. GitHub can render mermaid diagrams in issues, prs, discussions, wikis and markdown filesCheck your kwl repo before class and see if you have recieved feedback. Then, reply or merge accordingly.
Badges¶
Any steps in a badge marked lab are steps that we are going to focus in on during the next lab time. Remember the goal of lab is to help you complete the work, not add additional work. The lab checkout will include some other tasks and then we will encourage you to work on this badge while we are there to help. Lab checkouts are checked only for completion though, not correctness, so steps of activities that we want you to really think about and revise if incorrect will be in a practice or review badge.
Read the notes. If you have any questions, post an issue on the course website repo.
Using your terminal, download your KWL repo. Include the command(s) used in your badge PR.
Try using setting up git using your favorite IDE’s interface or GitHub Desktop. Make a file gitoffline.md in your kwl repo and include some notes of how it went. Was it hard? easy? what did you figure out or get stuck on? Is the terminology consistent or does it use different terms?
lab Explore the difference between git add and git commit: try committing and pushing without adding, then add and push without committing. Describe what happens in each case in a file called gitcommit.md. Compare what happens based on what you can see on GitHub and what you can see with git status.
Any steps in a badge marked lab are steps that we are going to focus in on during lab time. Remember the goal of lab is to help you complete the work, not add additional work. The lab checkout will include some other tasks and then we will encourage you to work on this badge while we are there to help. Lab checkouts are checked only for completion though, not correctness, so steps of activities that we want you to really think about and revise if incorrect will be in a practice or review badge.
Read the notes. If you have any questions, post an issue on the course website repo.
Using your terminal, download your KWL repo. Include the command used in your badge PR comment.
Try using setting up git using your favorite IDE’s interface or GitHub Desktop. Make a file gitoffline.md and include some notes of how it went. Was it hard? easy? what did you figure out or get stuck on? Is the terminology consistent or does it use different terms?
lab Explore the difference between git add and git commit: try committing and pushing without adding, then add and push without committing. Describe what happens in each case in a file called gitcommit_tips.md. Compare what happens based on what you can see on GitHub and what you can see with git status. Write a scenario with examples of how a person might make mistakes with git add and commit and what to look for to get unstuck.
Experience Report Evidence¶
You need to have a gh-inclass-... repo, have it cloned locally, with an about file and one commit.
Questions After Today’s Class¶
Is the local workspace used in the real world?¶
Yes, mostly in fact. Even if you work on e.g. an HPC system, you work locally on that system. You cannot run code on the git server, at all. Even github actions work “locally” just on a virtual machine.
Local is relative.
How can I see it in the folder of my desktop?¶
If you put your folder in your desktop folder, your regular file explorer or desktop should show.
If you mean desktop computer, like another physical device, you have to clone it there.
What’s a good way of memorizing the smaller commands?¶
Practice! and quizzing yourself.
We will practice, a lot in class and I’ll use prismia questions to quiz you some. Plus the review and practice badges will give you more instructions to practice with these commands.
How can I make a Pull Request to the course website repo?¶
at the top of the page there is a link to this repo (the github icon) but it’s also linked there.
Then find the file you want to add to (for this page, notes/2026-01-29.md) then use the pencil icon to edit. It will have you make a fork and then it will work just like a normal PR that we have done before.
Also the github docs have screenshots and more detailed instructions.
I do recommend trying to remember first though.