Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Snow day git miscellania

adding a remote when created locally

Last class we created tiny-book a jupyter-book. We’ll pick up there.

First, let’s review the contents

ls
_build			logo.png		references.bib
_config.yml		markdown-notebooks.md	requirements.txt
_toc.yml		markdown.md
intro.md		notebooks.ipynb

and make sure everything is okay with git:

git status
On branch main
nothing to commit, working tree clean
notice that it does not make a comparison to `origin` like we have seen typically; that's because there is no remote.

Let’s try git push

git push
fatal: No configured push destination.
Either specify the URL from the command-line or configure a remote repository using

    git remote add <name> <url>

and then push using the remote name

    git push <name>

This is similar to when we a branch we made locally and tried to push, but this time, we have to create the remote.

Let’s investigate a bit further:

ls .git/
COMMIT_EDITMSG	description	hooks		info		objects
config		HEAD		index		logs		refs

we have not yet looked at the config file.

let’s look now

cat .git/config
[core]
	repositoryformatversion = 0
	filemode = true
	bare = false
	logallrefupdates = true
	ignorecase = true
	precomposeunicode = true

git stores all of the important information for the program to know how to interpret the storage of the git objects.

Now, we create a repo on github in browser[1] and copy its url and then use the command like the error message above instructed. This repo is compeltely empty, it includes these instructions too.

git remote add origin https://github.com/compsys-progtools/tiny-book-brownsarahm-2.git

Now, if we use git remote with no subcommand, it lists the remote we just created!

git remote
origin

and with -v it shows us the full url

git remote -v
origin	https://github.com/compsys-progtools/tiny-book-brownsarahm-2.git (fetch)
origin	https://github.com/compsys-progtools/tiny-book-brownsarahm-2.git (push)

now, let’s try push again

git push
fatal: The current branch main has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin main

To have this happen automatically for branches without a tracking
upstream, see 'push.autoSetupRemote' in 'git help config'.

Let’s see what changed in the config

cat .git/config
[core]
	repositoryformatversion = 0
	filemode = true
	bare = false
	logallrefupdates = true
	ignorecase = true
	precomposeunicode = true
[remote "origin"]
	url = https://github.com/compsys-progtools/tiny-book-brownsarahm-2.git
	fetch = +refs/heads/*:refs/remotes/origin/*

We’ll use the shortcut for the --set-upstream option, -u that we found in the help (and a tip for from the github repo)

git push -u origin main
Enumerating objects: 14, done.
Counting objects: 100% (14/14), done.
Delta compression using up to 16 threads
Compressing objects: 100% (12/12), done.
Writing objects: 100% (14/14), 16.45 KiB | 16.45 MiB/s, done.
Total 14 (delta 1), reused 0 (delta 0), pack-reused 0 (from 0)
remote: Resolving deltas: 100% (1/1), done.
To https://github.com/compsys-progtools/tiny-book-brownsarahm-2.git
 * [new branch]      main -> main
branch 'main' set up to track 'origin/main'.
ls
_build			logo.png		references.bib
_config.yml		markdown-notebooks.md	requirements.txt
_toc.yml		markdown.md
intro.md		notebooks.ipynb

let’s edit the config

nano _config.yml

we’ll set our names as the author

_config.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# Book settings
# Learn more at https://jupyterbook.org/customize/config.html

title: My Tiny Book
author: Sarah M Brown
logo: logo.png

# Force re-execution of notebooks on each build.
# See https://jupyterbook.org/content/execute.html
execute:
  execute_notebooks: force

# Define the name of the latex output file for PDF builds
latex:
  latex_documents:
    targetname: book.tex

# Add a bibtex file so that we can create citations
bibtex_bibfiles:
  - references.bib

# Information about where the book exists on the web
repository:
  url: https://github.com/executablebooks/jupyter-book  # Online location of your book
  path_to_book: docs  # Optional path to your book, relative to the repository root
  branch: master  # Which branch of the repository should be used when creating links (optional)

# Add GitHub buttons to your book
# See https://jupyterbook.org/customize/config.html#add-a-link-to-your-repository
html:
  use_issues_button: true
  use_repository_button: true

Now we can re-build to get the change to show in the html

jupyter-book build .
Running Jupyter-Book v1.0.4.post1
Source Folder: /Users/brownsarahm/Documents/inclass/systems/tiny-book
Config Path: /Users/brownsarahm/Documents/inclass/systems/tiny-book/_config.yml
Output Path: /Users/brownsarahm/Documents/inclass/systems/tiny-book/_build/html
Running Sphinx v7.4.7
loading translations [en]... done
[etoc] Changing master_doc to 'intro'
loading pickled environment... checking bibtex cache... up to date
done
myst v3.0.1: MdParserConfig(commonmark_only=False, gfm_only=False, enable_extensions={'dollarmath', 'colon_fence', 'linkify', 'tasklist', 'substitution'}, disable_syntax=[], all_links_external=False, links_external_new_tab=False, url_schemes=('mailto', 'http', 'https'), ref_domains=None, fence_as_directive=set(), number_code_blocks=[], title_to_header=False, heading_anchors=0, heading_slug_func=None, html_meta={}, footnote_transition=True, words_per_minute=200, substitutions={}, linkify_fuzzy_links=True, dmath_allow_labels=True, dmath_allow_space=True, dmath_allow_digits=True, dmath_double_inline=False, update_mathjax=True, mathjax_classes='tex2jax_process|mathjax_process|math|output_area', enable_checkboxes=False, suppress_warnings=[], highlight_code_blocks=True)
myst-nb v1.3.0: NbParserConfig(custom_formats={}, metadata_key='mystnb', cell_metadata_key='mystnb', kernel_rgx_aliases={}, eval_name_regex='^[a-zA-Z_][a-zA-Z0-9_]*$', execution_mode='force', execution_cache_path='', execution_excludepatterns=[], execution_timeout=30, execution_in_temp=False, execution_allow_errors=False, execution_raise_on_error=False, execution_show_tb=False, merge_streams=False, render_plugin='default', remove_code_source=False, remove_code_outputs=False, scroll_outputs=False, code_prompt_show='Show code cell {type}', code_prompt_hide='Hide code cell {type}', number_source_lines=False, output_stderr='show', render_text_lexer='myst-ansi', render_error_lexer='ipythontb', render_image_options={}, render_figure_options={}, render_markdown_format='commonmark', output_folder='build', append_css=True, metadata_to_fm=False)
Using jupyter-cache at: /Users/brownsarahm/Documents/inclass/systems/tiny-book/_build/.jupyter_cache
sphinx-multitoc-numbering v0.1.3: Loaded
building [mo]: targets for 0 po files that are out of date
writing output... 
building [html]: targets for 4 source files that are out of date
updating environment: [config changed ('author')] 4 added, 0 changed, 0 removed
/Users/brownsarahm/Documents/inclass/systems/tiny-book/markdown-notebooks.md: Executing notebook using local CWD [mystnb]
/Users/brownsarahm/Documents/inclass/systems/tiny-book/markdown-notebooks.md: Executed notebook in 0.83 seconds [mystnb]
/Users/brownsarahm/Documents/inclass/systems/tiny-book/notebooks.ipynb: Executing notebook using local CWD [mystnb]
/Users/brownsarahm/Documents/inclass/systems/tiny-book/notebooks.ipynb: Executed notebook in 1.23 seconds [mystnb]

looking for now-outdated files... none found
pickling environment... done
checking consistency... done
preparing documents... done
copying assets... 
copying static files... done
copying extra files... done
copying assets: done
writing output... [100%] notebooks
generating indices... genindex done
writing additional pages... search done
copying images... [100%] _build/jupyter_execute/6dd0cd1655c6de15b65fe5aad8eab28fe9f845bcf6100d0fc4a46c2ae73d29f2.png
dumping search index in English (code: en)... done
dumping object inventory... done
build succeeded.

The HTML pages are in _build/html.

===============================================================================

Finished generating HTML for book.
Your book's HTML pages are here:
    _build/html/
You can look at your book by opening this file in a browser:
    _build/html/index.html
Or paste this line directly into your browser bar:
    file:///Users/brownsarahm/Documents/inclass/systems/tiny-book/_build/html/index.html            

===============================================================================

Make a repo that you are the owner of and add that too:

git remote add personal https://github.com/brownsarahm/tiny-book.git

we can have multiple remotes. Think about how these relate to the

git remote
origin
personal
git remote -v
origin	https://github.com/compsys-progtools/tiny-book-brownsarahm-2.git (fetch)
origin	https://github.com/compsys-progtools/tiny-book-brownsarahm-2.git (push)
personal	https://github.com/brownsarahm/tiny-book.git (fetch)
personal	https://github.com/brownsarahm/tiny-book.git (push)

and it stores them both in the config:

cat .git/config
[core]
	repositoryformatversion = 0
	filemode = true
	bare = false
	logallrefupdates = true
	ignorecase = true
	precomposeunicode = true
[remote "origin"]
	url = https://github.com/compsys-progtools/tiny-book-brownsarahm-2.git
	fetch = +refs/heads/*:refs/remotes/origin/*
[remote "personal"]
	url = https://github.com/brownsarahm/tiny-book.git
	fetch = +refs/heads/*:refs/remotes/personal/*

What else can git tell me?

Let’s start in the gh inclass reop

cd ../gh-inclass-sp26-brownsarahm/
git status
On branch main
Your branch is ahead of 'origin/main' by 3 commits.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean

we can get an idea of hwat those commits contain with the log

git log -n 3 --pretty=oneline
cbdb5fc52d22037f51eeac8cb533c0b526789ba8 (HEAD -> main, origin/organize, organize) remove extra >
d1c1df80396c1eb7f395dad955f83f6dd995861e  start organizing
219c49c573315e67e15c080f0c03271bbb7a8cd2 add title to readme

git diff gives us more details about the chnges over a set of commits (or other points... we’ll see later)

git diff 219c..cbdb README.md
diff --git a/README.md b/README.md
index 1ec17bc..49e94cc 100644
diff --git a/README.md b/README.md
index 1ec17bc..49e94cc 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +1,21 @@
 [![Open in Codespaces](https://classroom.github.com/assets/launch-codespace-2972f46106e565e64193e422d61a12cf1da4916b45550586e14ef0a7c637dd04.svg)](https://classroom.github.com/open-in-codespaces?assignment_repo_id=22432670)
 # Readme
+|file | contents |
+| --| -- |
+| abstract_base_class.py | core abstract classes for the project |
+| helper_functions.py | utitly funtions that are called by many classes |
+| important_classes.py | classes that inherit from the abc |
+| alternative_classes.py | classes that inherit from the abc |
+| LICENSE.md | the info on how the code can be reused|
+| CONTRIBUTING.md | instructions for how people can contribute to the project|
+| setup.py | file with function with instructions for pip |
+| test_abc.py | tests for constructors and methods in abstract_base_class.py|
+| tests_helpers.py | tests for constructors and methods in helper_functions.py|
+| tests_imp.py | tests for constructors and methods in important_classes.py|
+| tests_alt.py | tests for constructors and methods in alternative_classes.py|
+| API.md | jupyterbook file to generate api documentation |
+| _config.yml | jupyterbook config for documentation |
+| _toc.yml | jupyter book toc file for documentation |
+| philosophy.md | overview of how the code is organized for docs |
+| example.md | myst notebook example of using the code |
+| scratch.ipynb | jupyter notebook from dev |

now let’s edit the file:

nano README.md
README.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
[![Open in Codespaces](https://classroom.github.com/assets/launch-codespace-2972f46106e565e64193e422d61a12cf1da4916b45550586e14ef0a7c637dd04.svg)](https://classroom.github.com/open-in-codespaces?assignment_repo_id=22432670)
# Readme

this repo contains the files as below

|file | contents |
| --| -- |
| abstract_base_class.py | core abstract classes for the project |
| helper_functions.py | utitly funtions that are called by many classes |
| important_classes.py | classes that inherit from the abc |
| alternative_classes.py | classes that inherit from the abc |
| LICENSE.md | the info on how the code can be reused|
| CONTRIBUTING.md | instructions for how people can contribute to the project|
| setup.py | file with function with instructions for pip |
| test_abc.py | tests for constructors and methods in abstract_base_class.py|
| tests_helpers.py | tests for constructors and methods in helper_functions.py|
| tests_imp.py | tests for constructors and methods in important_classes.py|
| tests_alt.py | tests for constructors and methods in alternative_classes.py|
| API.md | jupyterbook file to generate api documentation |
| _config.yml | jupyterbook config for documentation |
| _toc.yml | jupyter book toc file for documentation |
| philosophy.md | overview of how the code is organized for docs |
| example.md | myst notebook example of using the code |
| scratch.ipynb | jupyter notebook from dev |

We can use git diff with no references to compare the last commit to the current working directory. This can be helpful when you’re planning your commit message.

git diff
diff --git a/README.md b/README.md
index 49e94cc..da455ad 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,8 @@
 [![Open in Codespaces](https://classroom.github.com/assets/launch-codespace-2972f46106e565e64193e422d61a12cf1da4916b45550586e14ef0a7c637dd04.svg)](https://classroom.github.com/open-in-codespaces?assignment_repo_id=22432670)
 # Readme
+
+this repo contains the files as below
+
 |file | contents |
 | --| -- |
 | abstract_base_class.py | core abstract classes for the project |
git status
On branch main
Your branch is ahead of 'origin/main' by 3 commits.
  (use "git push" to publish your local commits)

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	modified:   README.md

no changes added to commit (use "git add" and/or "git commit -a")
git commit -a -m 'describe table'
[main 694223d] describe table
 1 file changed, 3 insertions(+)

What about goign backwards

git revert lets use add a new commit that contains the opposite changes of the commit that we want to revert.

For example, my commit 694223d adds the table description, so reverting will remove it.

git revert 694223d
[main ccbb750] Revert "describe table"
 1 file changed, 3 deletions(-)

notice there is a new commit with the revert:

git log -n 5 --pretty=oneline
ccbb75084ba081ba5ad1dd16349315ca268157a0 (HEAD -> main) Revert "describe table"
694223d2741c9bb24ee0ac2abc5934be80429614 describe table
cbdb5fc52d22037f51eeac8cb533c0b526789ba8 (origin/organize, organize) remove extra >
d1c1df80396c1eb7f395dad955f83f6dd995861e  start organizing
219c49c573315e67e15c080f0c03271bbb7a8cd2 add title to readme

and the file is as before

cat README.md
[![Open in Codespaces](https://classroom.github.com/assets/launch-codespace-2972f46106e565e64193e422d61a12cf1da4916b45550586e14ef0a7c637dd04.svg)](https://classroom.github.com/open-in-codespaces?assignment_repo_id=22432670)
# Readme
|file | contents |
| --| -- |
| abstract_base_class.py | core abstract classes for the project |
| helper_functions.py | utitly funtions that are called by many classes |
| important_classes.py | classes that inherit from the abc |
| alternative_classes.py | classes that inherit from the abc |
| LICENSE.md | the info on how the code can be reused|
| CONTRIBUTING.md | instructions for how people can contribute to the project|
| setup.py | file with function with instructions for pip |
| test_abc.py | tests for constructors and methods in abstract_base_class.py|
| tests_helpers.py | tests for constructors and methods in helper_functions.py|
| tests_imp.py | tests for constructors and methods in important_classes.py|
| tests_alt.py | tests for constructors and methods in alternative_classes.py|
| API.md | jupyterbook file to generate api documentation |
| _config.yml | jupyterbook config for documentation |
| _toc.yml | jupyter book toc file for documentation |
| philosophy.md | overview of how the code is organized for docs |
| example.md | myst notebook example of using the code |
| scratch.ipynb | jupyter notebook from dev |
git config --help
git log -n 10 --pretty=oneline
ccbb75084ba081ba5ad1dd16349315ca268157a0 (HEAD -> main) Revert "describe table"
694223d2741c9bb24ee0ac2abc5934be80429614 describe table
cbdb5fc52d22037f51eeac8cb533c0b526789ba8 (origin/organize, organize) remove extra >
d1c1df80396c1eb7f395dad955f83f6dd995861e  start organizing
219c49c573315e67e15c080f0c03271bbb7a8cd2 add title to readme
ba7a1e6b5fbd737d7ecb2cd54e32866121a476aa (origin/main, origin/HEAD) Merge pull request #6 from compsys-progtools/organizing_ac
ce430e9745738c4b8818e2d527d303ca1b5d0f9e (origin/organizing_ac) add files for organizing activity
f6886babaa283a8238632930bf2cca9121fc274b (my_branch_checkedoutb, my_branch) Merge pull request #5 from compsys-progtools/2-create-an-about-file
cfd464dc22568fcff6aa302fbd6025e44b7262ac (origin/2-create-an-about-file, 2-create-an-about-file) Update about.md
a254c24301bc02c9624726573e902c8ffe437a0b create empty about
cd ..
ls
demo				kwl-sp26-brownsarahm
gh-inclass-sp26-brownsarahm	tiny-book

we can allos check out specific commits

git checkout cbdb
Note: switching to 'cbdb'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at cbdb5fc remove extra >

Other reerences

We have seen that branches are pointers to commits that move. Tags are pointers to commits that do not move:

git tag v1
git checkout main
Previous HEAD position was cbdb5fc remove extra >
Switched to branch 'main'
Your branch is ahead of 'origin/main' by 5 commits.
  (use "git push" to publish your local commits)
git log -n 10 --pretty=oneline
ccbb75084ba081ba5ad1dd16349315ca268157a0 (HEAD -> main) Revert "describe table"
694223d2741c9bb24ee0ac2abc5934be80429614 describe table
cbdb5fc52d22037f51eeac8cb533c0b526789ba8 (tag: v1, origin/organize, organize) remove extra >
d1c1df80396c1eb7f395dad955f83f6dd995861e  start organizing
219c49c573315e67e15c080f0c03271bbb7a8cd2 add title to readme
ba7a1e6b5fbd737d7ecb2cd54e32866121a476aa (origin/main, origin/HEAD) Merge pull request #6 from compsys-progtools/organizing_ac
ce430e9745738c4b8818e2d527d303ca1b5d0f9e (origin/organizing_ac) add files for organizing activity
f6886babaa283a8238632930bf2cca9121fc274b (my_branch_checkedoutb, my_branch) Merge pull request #5 from compsys-progtools/2-create-an-about-file
cfd464dc22568fcff6aa302fbd6025e44b7262ac (origin/2-create-an-about-file, 2-create-an-about-file) Update about.md
a254c24301bc02c9624726573e902c8ffe437a0b create empty about

Tags have to be pushed (and pulled) explicitly

git push --tags
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)
To https://github.com/compsys-progtools/gh-inclass-sp26-brownsarahm.git
 * [new tag]         v1 -> v1

Prepare for Next Class

Quiz yourself to be sure you remember the following:

In particular, review the following class sessions

create a midsemreview.md with your answers to the questions.

Badges

Review
Practice
  1. Review the notes from today

  2. Use git bisect to find the first bad commit in the toy bug repo, save the command history and the bad commit hash to git_debug.md

  3. Determine how many of the tags in the course website are annotated vs lightweight using (hint: annotated are objects, lightweight just point to commits). (You may need to use git pull --tags in your clone of the course website)

# Tags

<!-- short defintion/description in your own words of what a tag is and what it is for -->


## Comparing tag types 

<!-- include your experiment terminal history  and interpretation -->

## Inspecting tags

Course website tags by type: 
- annoted:
- lightweight: 
<!-- include lists of tags for each type -->

build idea create tool that can automatically generate a set of files, and make commits, including one that is the “error”, so that each student could run a local command and get a repo with the error at a different point, for a more personalized version of the toy bug exercise.

Experience Report Evidence

Questions After Today’s Class

Footnotes