3. Why Systems?#
3.1. 5 minutes#
3.2. Questions?#
Issues, Pull requests, Prepare, Practice, Review, Lab…
3.3. Working offline#
Today more clear motivation for each thing we do and more context.
Today we will learn to work with GitHub 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
3.4. Let’s get organized#
For class you should 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 mac, 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 commandbash
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
(preferred)if you have WSL (if you do not, no need to worry) you should be able to set your linux shell to
bash
(I believe it already is set to bash)
If you use pwd
you can see your current path
pwd
Users/ayman
It outputs the absolute path of the location that I was at.
we start at home ~
We can change directory with cd
if we use cd
without a path, it goes back to home cd ~
would do the same
We can mak a new directory with mkdir
What you want to have is a folder for class (mine is systems) in a place you can find it
You might:
make a systems folder in your Documents folder
make an inclass folder in the CSC311 folder you already made
use the CSC311 folder as your in class working space
If I run the following commands, what do I expect as the output?
cd
pwd
[ ] cannot tell, do not know where you started
[x] /c/Users/ayman
[ ] /c/Users/ayman/Documents
[ ] the same as whereever you were before
When you use pwd
what type of path does it return?
[x] absolute
[ ] relative
The first slash /
represents the /(root)
directory, which is the starting place for the search
But what does it mean when a path starts with .
or ..
?
To go back one step in the path, (one level up in the tree) we use cd ..
cd ..
..
is a special file that points to a specific relative path, of one level up. (In other words, parent folder/directory)
use pwd
, cd
and pwd
to illustrate what “one level up” means
Did you notice the dieffernce?
cds Documents/
bash: cds: command not found
notice that command not found is the error when there is a typo
cd Documents/
pwd
/c/Users/ayman/Documents
mkdir systems
/c/Users/ayman/Documents/systems
cd ..
pwd
/c/Users/ayman/Documents/
If we give no path to cd
it brings us to home.
cd
pwd
/c/Users/ayman
Then we can go back.
cd Documents/systems/
pwd
/c/Users/ayman/Documents/systems
Do you have any content in the folder?
ls
Could be empty of if you had created it before you would see the content you had in it
We can use two levels up at once like this:
cd ../../
pwd
/c/Users/ayman
cd Documents/systems/
We can the tab
to complete once we have a unique set of characters. If what we have is not unique enoguh yet, bash will do nothing when you press tab once, but if you press it multiple tiems it will show you the options:
cd Do
Press tab
twice.
The consol outputs:
Documents/ Downloads/
cd Do
cd Doc
Press tab
…
The consol auto completes the path
cd Documents/
What character is always at the start of absolute paths?
[ ] :
[x] /
[ ] *
[ ] ]
What type of path is ../../Downloads
?
[ ] absolute
[x] relative
3.5. 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
Preferred:
click the green “use this template” button in the top right
make
compsys-progtools
the ownerset the name to
gh-inclass-<your gh username>
replacing the<>
part with your actual name
Backup: accept the assignment
3.6. Authenticating with 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
For a public repo, it won’t matter, you can use any way to download it that you wuold like, but for a private repo, we need to be authenticated.
3.6.1. Authenticating with GitHub#
There are many ways to authenticate securely with GitHub and other git clients. We’re going to use easier ones for today, but we’ll come back to the third, which is a bit more secure and is a more general type of authentication.
ssh keys (we will do this later)
gh
CLI withgh auth login
we will do opiton 2 for today
3.6.1.1. GitBash (windows mostly)#
git clone
and paste your URL from GitHubthen follow the prompts, choosing to authenticate in Browser.
3.6.1.2. Native terminal ( MacOS X/Linux/WSL)#
GitHub CLI: enter
gh auth login
and follow the prompts.then
git clone
and paste your URL from github
3.6.1.3. 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
3.6.2. Cloning a repository#
We will create a local copy by cloning
Type pwd
first to make sure you’re in the Systems folder
git clone https://github.com/compsys-progtools/gh-inclass-AymanBx
Cloning into 'gh-inclass-AymanBx`...
remote: Enumerating objects: 8, done.
remote: Counting objects: 100% (8/8), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 8 (delta 0), reused 4 (delta 0), pack-reused 0
Receiving objects: 100% (8/8), done.
Confirm it worked with:
ls
gh-inclass-AymanBx
We see the new folder that matches our repo name
3.7. What is in a repo?#
We can enter that folder
cd gh-inclass-AymanBx/
When we compare the local directory to GitHub
ls
Notice 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 of the files or folders with the -a
for all option or flag. Options are how we can pass non required parameters to command line programs.
ls -a
. .git
.. .github
We also see some special “files”, .
the current location and ..
up one directory
3.8. How do I know what git knows?#
git status
is your friend.
git status
On branch main
Your branch is up to date with 'origin/main'.
nothing to commit, working tree clean
this 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 (more on that later …).
3.9. Making a branch with GitHub and working offline#
First on an 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.
“create an about file”
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 origin
From https://github.com/compsys-progtools/gh-inclass-AymanBx
* [new branch] 1-create-an-about-file -> origin/1-create-an-about-file
We can look at the repo to see what has changed.
git status
On branch main
Your branch is up to date with 'origin/main'.
nothing to commit, working tree clean
This says nothing, because remember git status tells us the relationship between our working directory and the .git repo.
Next, we switch to that branch.
git checkout 1-create-an-about-file
branch '1-create-an-about-file' set up to track 'origin/1-create-an-about-file'.
Switched to a new branch '1-create-an-about-file'
and verify what happened
git status
On branch 1-create-an-about-file
Your branch is up to date with 'origin/1-create-an-about-file'.
nothing to commit, working tree clean
Run your Experience Badge (inclass) action. Github how to
Go to the Actions tab
Click the Experience Badge (inclass) on the left hand side
Click the run workflow button on the right
Click the run workflow button in the popup
3.10. Prepare for next class#
Find the glossary page for the course website, link it below. 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.md
on a branch linked to this issue.Check your kwl repo before class and see if you have recieved feedback, reply or merge accordingly.
3.11. Example#
Example “venn diagram “ with mermaid subgraphs
3.12. 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 used in your badge PR.
Try using setting up git using your favorite IDE 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.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 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.