How can I use GitHub offline?
Contents
3. How can I use GitHub offline?#
3.1. Get Organized#
Opening different terminals
terminal app on mac, use the
bash
command to use bash (zsh will be mostly the same; it’s derivative, but to ensure exactly the same as mine use bash)use gitbash on Windows
We can move around and examine the computer’s file structure using shell commands.
cd
is for change directory. We can use the relative path to get to where we
want to go. We can see what files and folder are at our curent location with ls
if we need a reference.
cd Documents/inclass/
We can use ls in the folder we get to. I chose to go to a place where I save content I use during my classes that I teach.
ls
I already have a folder for the other class:
prog4ds
I need a folder for this class, so I will make one with mkdir
mkdir systems
To view where we are, we print working directory
pwd
It prints out the absolute path, that begins with a /
above, we used a relative
path, from the home directory.
/Users/brownsarahm/Documents/inclass
Checkin
What is the absolute path of the home directory?
Next I will go into the folder I just made
cd systems/
3.2. Issues and Commits#
create a test repo for today’s class
First we’re going to see how issues and commits relate.
Let’s create the README on github and make a pull request with closes #1
in the PR
message.
Notice what happened:
the file is added and the commit has the the message
the issue is closed
if we go look at the closed issues, we can see on the issue that it was linked
from the issue, we can see what the changes were that made are supposed to relate to this
we can still comment on an issue that is already closed.
3.3. Authenticating with GitHub and cloning a repo#
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.
Depending on how you have authenticated with GitHub, a different version of the URL will be highlighted.
For today, if you have ssh keys already set up, use that.
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.
GitHub CLI: enter the following and follow the prompts.
gh auth login
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)
ssh keys
GitBash built in authentication
Or we can use use the GitHub CLI tool to authenticate.
On Mac with GitHub CLI:
gh auth login
On Windows, Try the clone step and then follow the authentication instructions.
On Mac, clone after you are all logged in.
git clone https://github.com/introcompsys/github-inclass-brownsarahm.git
Cloning into 'github-inclass-brownsarahm'...
remote: Enumerating objects: 9, done.
remote: Counting objects: 100% (9/9), done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 9 (delta 0), reused 4 (delta 0), pack-reused 0
Receiving objects: 100% (9/9), done.
We can also see that it created a new folder:
ls
github-inclass-brownsarahm
3.4. What is in a repo?#
We can enter that folder
cd github-inclass-brownsarahm/
and see what is inside
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.
the -a
option allows us to see them
ls -a
We also see some special “files”, .
the current location and ..
up one directory
. .. .git .github README.md
3.5. Relative paths#
We can see clearly where ..
goes by printing our our location before and
after changing directory to ..
pwd
/Users/brownsarahm/Documents/inclass/systems/github-inclass-brownsarahm
cd ..
pwd
/Users/brownsarahm/Documents/inclass/systems
3.6. Adding a file from the command line#
First back to the repo directory
cd github-inclass-brownsarahm/
We will make an empty file for now, using touch
touch about.md
ls
We can se the two folders
README.md about.md
We can see the file, but what does git know?
git status
On branch main
Your branch is up to date with 'origin/main'.
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)
First we have to add it to a staging are to make a batch of files (or only one) that will commit.
git add .
THen we check in with git again
git status
On branch main
Your branch is up to date with 'origin/main'.
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: about.md
THen we can commit the file
git commit -m "create about"
Git returns to us the commit number, with the message and a summary
[main 3c9980a] create about
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 about.md
and again checkin
git status
On branch main
Your branch is ahead of 'origin/main' by 1 commit.
(use "git push" to publish your local commits)
nothing to commit, working tree clean
Now we see that the local copy is ahead of GitHub (aka origin), so we need to push to make the changes go to GitHub.
git push
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 8 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 307 bytes | 307.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To https://github.com/introcompsys/github-inclass-brownsarahm.git
ec3dd02..3c9980a main -> main
(base) brownsarahm@github-inclass-brownsarahm $
3.7. Review#
Follow along with the classmate issue in your inclass repo from today. Work with someone you know or find a collaborator in the Discussion board
read the notes
try using git in your IDE of choice, Share a tip in the course discussion repo
3.8. Prepare#
Make a list of 3-5 terms you have learned so far and try defining them in your own words.
using your terminal, download your KWL repo and update your ‘learned’ column on a new branch do not merge this until instructed
answer the questions below in a new markdown file, called
gitreflection.md
in your KWL
Questions:
## Reflection
1. Describe the staging area (what happens after git add) in your own words. Can you think of an analogy for it? Is there anything similar in a hobby you have?
2. what step is the hardest for you to remember?
3. Compare and contrast using git on the terminal and through your IDE. when would each be better/worse?
3.9. More Practice#
Download the course website and your group repo via terminal. Try these on different days to get “sapced repetition” and help remember better.
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 your gitoffline.md
3.10. Questions at the end of class#
• can you add additional arguments to most git commands? ex git commit -…
• why can’t we make all of these files on github instead of using gitbash?
• is there any advantages to using the github website vs using the github commands on your terminal
• One question I have is, how would I edit a text file using bash
• When working with a team what are ways we can prevent merging conflicts?
• will we do the bulk of our work in-console or in an IDE, or a mix of both?
• none
• If we are confused about what is due for next class, which locations should we look? I think right now there are multiple, unless I am wrong about that.
• I accidentally used the push command before the config command. Is that a problem? Is there anything I have to change?