3. Bash intro & git offline#
3.1. Open a Terminal#
Use Git for Windows aka GitBash. This program emulates bash for you.
Your linux terminal should work.
On mac open a terminal window. By default your terminal uses zsh. You may change to bash using the bash
command or use zsh
. They are mostly the same.
My terminal reminds me that using bash is not Apple’s preference
Last login: Sun Jan 29 11:50:33 on ttys017
The default interactive shell is now zsh.
To update your account to use zsh, please run `chsh -s /bin/zsh`.
For more details, please visit https://support.apple.com/kb/HT208050.
3.2. Getting Organized.#
To view where we are, we print working directory using pwd
.
pwd
As output we see:
/Users/brownsarahm
It prints out the absolute path, that begins with a /
above, we used a relative
path, from the home directory.
Next I can change directory with cd
. To do this, I could use an absolute path of where I want to go or I can use the relative path which is the directions from one location to another.
cd Documents/inclass/
Here I can list the files.
ls
fa22 prog4dssp23
Next we’ll make a folder for this course
mkdir systems
Note that making the new folder does not move us into it.
pwd
/Users/brownsarahm/Documents/inclass
For that,we use cd
again.
cd systems/
This is an emptry folder, we can confirm with:
ls
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.
cds systems/
bash: cds: command not found
notice that command not found is the error when there is a typo
cd systems/
pwd
/Users/brownsarahm/Documents/inclass/systems
cd ..
pwd
/Users/brownsarahm/Documents/inclass
If we give no path to cd
it brings us to home.
cd
pwd
/Users/brownsarahm
Then we can go back.
cd Documents/inclass/systems/
pwd
/Users/brownsarahm/Documents/inclass/systems
We can use two levels up at once like this:
cd ../../
pwd
/Users/brownsarahm/Documents
cd inclass/systems/
3.3. 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
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.3.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
GitBash built in authentication
Skip straight to clone, then follow the prompts, choosing to authenticate in Browser.
GitHub CLI: enter the following and follow the prompts.
```
gh auth login
```
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.3.2. Cloning a repository#
We will create a local copy by cloning
git clone https://github.com/introcompsys/github-in-class-brownsarahm-1.git
Cloning into 'github-in-class-brownsarahm-1'...
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
github-in-class-brownsarahm-1
We see the new folder that matches our repo name
3.4. What is in a repo?#
We can enter that folder
cd github-in-class-brownsarahm-1/
When we compare the local directory to GitHub
ls
README.md
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 with the -a
for all option or flag. Options are how we can pass non required parameters to command line programs.
ls -a
. .git README.md
.. .github
We also see some special “files”, .
the current location and ..
up one directory
3.5. Review today’s class#
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.
Reorganize a folder on your computer ( good candidate may be desktop or downloads folder), using only a terminal to make new directories, move files, check what’s inside them, etc. Answer reflection questions (will be in notes) in a new file,
terminal.md
in your kwl repo. Start with a file explorer open, but then try to close it and use only command line tools to explore and make your choices. If you get stuck, make notes.
### Terminal File moving reflection
1. Did this get easier toward the end?
1. What if anything did you get stuck on
1. When do you think that using the terminal will be better than using your GUI file explorer?
3.6. Prepare for Next Class#
Make a list of questions you have about using the terminal
Be prepared to compare and contrast bash, shell, terminal, and git.
(optional) If you like to read about things before you do them, read about merge conflicts. If you prefer to see them first, come to class on Thursday and read this after.
3.7. More Practice#
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.
Reorganize a folder on your computer ( good candidate may be desktop or downloads folder), using only a terminal to make new directories, move files, check what’s inside them, etc. Answer reflection questions (will be in notes) in a new file,
terminal.md
in your kwl repo. Start with a file explorer open, but then try to close it and use only command line tools to explore and make your choices. If you get stuck, look up additional commands to do acomplish your goals.
### Terminal File moving reflection
1. Did this get easier toward the end?
1. Use the `history` to see which commands you used and how many times each, make a table below.
1. Did you have to look up how to do anything we had not done in class?
1. When do you think that using the terminal will be better than using your GUI file explorer?
1. What questions/challenges/ relfections do you have after this?
1. What kinds of things might you want to write a bash script for given what you know in bash so far? come up with 1-2 scenarios
3.8. Experience Report Evidence#
To show you completed this activity, show the output of the following commands in evidence-2023-01-31.md
in the `experiences folder:
cd path/you/choce/systems
where you replace the path/you/chose
accordingly
ls
cd github-inclass-<yourghusername>
with your gh username
ls -a
3.9. Questions After Today’s Class#
3.9.1. Questions we will answer next class#
How do changes that I do to the repo offline update on the github website?
Does github connect to a file automatically or do i have to connect it manual
What other command options/flag examples like ls -a?
When we make changes to our cloned repository, do we need to make commits/pull requests within gitbash, or the equivalent, in order for the changes to showup on the browser github?
3.9.2. Questions I need clarification from you to be able to answer#
probably go to office hours
I would like more clarification on how to navigate the experience reflection badge.
Why is nothing working lol. I tried downloading the github thing from the command line and nothing worked
After downloading homebrew, the “gh auth login” still doesn’t work.
3.9.3. Why is SSH less secure than the HTTPS standard?#
SSH keys are secure, but other shell things are not. Using SSH keys is acutally preferred, but you cannot do other types of command line password operations with GitHub. git alone, does support HTTPS connection with passwords, but GitHub no longer does. It only allows you to use PAT (a temporary password), SSH keys, or using the GitHub CLI tool to use your browser. We will use SSH keys later.
3.9.4. Why would we want to create files from Git Bash terminal as opposed to File Explorer or CMD Prompt#
bash is not operating specific, so using bash commands can work on more systems including most servers, while CMD commands can only work on Windows (and basically no servers). File explorer is fine one file at a time, but you cannot automate it.
3.9.5. How do you move folders into other folders in terminal once you’ve created them?#
The mv
command does this. see its documentation
3.9.6. Is there an easy way to remember shortcuts for terminal?#
Lots of practice.
3.9.7. is GitHub desktop used less often than git via command line?#
I would say yes for a few reasons:
I think only novices and nonprogrammers use GitHub desktop extensively.
It has fewer features.
It’s not typically avialable on a server.
It only works with GitHub, not other servers
The GitHub specific CLI, I do not have a good sense of how often it is used.