9. What is git?#

9.1. Admin#

9.1.1. get credit for this class toward your major#

If you have not already [get the “curriculum modification” form from the college]](https://web.uri.edu/artsci/academics/student-resources/forms/). Fill it out in the following way:

9.1.2. Progress#

  • find an issue from me on your KWL repo with titled “progress as of 2023-02-18 HH:MM:SS” ask questions there.

  • merge PR from me titled “udpate experience report action”

Important

read comments carefully, if we correct something for you a few times and you continue to frequently make the same error, we will stop approving work with that error**

9.1.3. Logistics Clarification#

badge info

Warning

The bottom of the page had rendering issues during class, but is fixed now.

9.2. Git is a File system#

Important

git book is the official reference on git.

this includes other spoken languages as well if that is helpful for you.

git is fundamentally a content-addressable filesystem with a VCS user interface written on top of it.

Content-addressable filesystem means a key-value data store.

what types of programming have you seen that use key- value pairs?
  • python dictionaries

  • pointers (address,content)

  • parameter, passed values

Python 3.8.3 (default, Jul  2 2020, 11:26:31) 
[Clang 10.0.0 ] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> md = {'key1':1}
>>> md[key1]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'key1' is not defined
>>> md['key1']
1
>>> exit()

What this means is that you can insert any kind of content into a Git repository, for which Git will hand you back a unique key you can use later to retrieve that content.

9.3. Git is a Version Control System#

git stores snapshots of your work each time you commit.

snapshot of 5 version sof 3 files

it uses 3 stages:

3 stages in git

9.4. Git has two sets of commands#

Porcelain: the user friendly VCS

Plumbing: the internal workings- a toolkit for a VCS

We have so far used git as a version control system. A version control system, in general, will have operations like commit, push, pull, clone. These may work differently under the hood or be called different things, but those are what something needs to have in order to keep track of different versions.

The plumbing commands reveal the way that git performs version control operations. This means, they implement file system operations for the git version control system.

You can think of the plumbing vs porcelain commands like public/private methods. As a user, you only need the public methods (porcelain commands) but those use the private ones to get things done (plumbing commands). We will use the plumbing commands over the next few classes to examine what git really does when we call the porcelain commands that we will typically use.

9.5. Git is distributed#

What does that mean?

Git runs locally. It can run in many places, and has commands to help sync across remotes, but git does not require one copy of the repository to be the “official” copy and the others to be subordinate. git just sees repositories.

For human reasons, we like to have one “official” copy and treat the others as local copies, but that is a social choice, not a technological requirement of git. Even though we will typically use it with an offical copy and other copies, having a tool tht does not care, makes the tool more flexible and allows us to create workflows, or networks of copies that have any relationship we want.

It’s about the workflows, or the ways we socially use the tool.

Some example workflows

9.5.1. Subversion WOrkflow#

subversion workflow

9.5.2. Integration Manager#

integration manager workflow

9.5.3. dictator and lieutenants#

dictator and lieutenants workflow

9.6. How does git do all these things?#

Let’s look at git again in our github-inclass repo

cd ../github-in-class-brownsarahm-1/

We can use the bash command find to search the file system note that this does not search the contents of the files, just the names.

find objects/ -type f
objects//0d/d61172a7dad0ac78ed6ca1788130a607983973
objects//66/63ed3256515f3b45209c380c76bc2c47225175
objects//57/de0cd87ec14926273fd4760b94c0ea6f5b87d3
objects//03/29e78f9f8cc84f80808b907b044295f1f82594
objects//6a/2e1cc65204d0c05acc477e7d5e704f989a68dc
objects//56/f29cad4c33dc9e5c194e6f774024bca756b6ee
objects//34/6853b8cf891a2783619506221965ffd35ed99d
objects//5f/3e4cc9381a15bf59b928af1381cb5f2518cedb
objects//9d/b284a866b196a79fd633c439b1dce783740137
objects//9c/b0323be29dab2db451e9975fa2e65b37190ff1
objects//d9/328fbe3ec302b590077eee7ad599b7dc246685
objects//bb/4e0d87b6dc7d6c48e5515f6a52cc05948ca9e3
objects//df/d1d047143ec437b431560e2ba8e7eb0c0d514f
objects//a2/fdcfaa06f1c56dac80df0cef908423b425ee4a
objects//bc/dc409a2e646854230114127ab8ad2f336668db
objects//f2/844b2a9c31f83e589a73c1c1b8bd7696c8cf64
objects//e3/cd28cf87c8f6c40529b4687cda50776970c829
objects//cf/fcf05fdee460b85057ae3716ce1f10ac205a22
objects//c1/b4b79b8bdd8e4496ea42bedcf143d22aea7e03
objects//4b/89dffc186f530de628673b199676a097d6d13c
objects//pack/pack-f37aaf1cb9275265234c59965db2dc9400655294.idx
objects//pack/pack-f37aaf1cb9275265234c59965db2dc9400655294.pack
objects//7c/3f99d89aafd49b67e50baf15adae32a3390ca5
objects//45/fcb1dd311e5e45af759cb3627dca5f47f58f04
objects//10/d85a79160a778436092df1706244394ba8376e
objects//81/2245d1177f889dd3ea2e20da6ac104085d25a3
objects//00/96423976e05d13728aa27490d6dd2d2840cc84
objects//98/96f7a7000a7b9d2fdb12047a141524358286c3
objects//5e/373ecaa68320f4fb5cfec60a0d46dd68084693
objects//5b/0dbbf0e8590575ff3fe8e9df38d140ce2e2948
objects//01/69e39a61bde682786d77bcde127fde0ff35d10
objects//6c/96898a9a0a0d5c5f1a38311a919b9b950aa05c
objects//64/0b6939d6dcfb9256e4f070f292f75c32bc8f59
objects//b8/f98b0f8093179f9374bcadd9b6ebe9a5bf274f
objects//ef/45e7786b3fab07e387ed8dda483d536d6fde1f
objects//e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391
objects//f7/9afa4312d6903db0c6ad33aaca79a93dadd0c3
objects//e8/2ebb4066f0a6ae070b2f68d13bfbad2f9a6835
objects//fa/eef5ba81b606bf348f1a4e72683b0f8d71b5e4
objects//c5/d4dbaf3808a86af355490f4251ee020d8b7057
objects//c2/8b4ad71b16469c755dba11a1021703a3703212
objects//f8/c5f11ce099748ff751d5535fec38871895a153
objects//70/0ecda4eea6263b886e3ce5faa48ade2079f1d0
objects//23/754587e413b5e75b96665b21b7e9a6404c4026
objects//4f/a9114632f26ec590eec7e91712596085d7c442
objects//12/bbbadd5e636eb345c891e044d4231912085fe4
objects//76/175a40431fa6596e046795f46590208bb04232
objects//47/0d497ce7c645a4646ae7f95999846988546440
objects//78/b2aa7505031c06c109ff8bb2b0a8a1173c0652
objects//8e/2fe11b4ed5ac39b22f680a4c627fd88a6628fd

This is a lot of files! It’s more than we have in our working directory.

cd ..
ls
API.md			docs
CONTRIBUTING.md		greeting.md
LICENSE.md		helper_functions.py
README.md		important_classes.py
about.md		setup.py
abstract_base_class.py	tests
alternative_classes.py

This is a consequence of git taking snap shots and tracking both the actual contents of our working directory and our commit messages and other meta data about each commit.

9.7. Git HEAD#

First lets get a a clean working directory

Note

MY first git status was not a clearn up to date working tree. I took the steps to get there

git status
On branch main
Your branch is up to date with 'origin/main'.

nothing to commit, working tree clean

the program git does not run continously the entire time you are using it for a project. It runs quick commands each time you tell it to, it’s goal is to manage files, so this makes sense. This also means that important information that git needs is also saved in files.

cd .git
ls
COMMIT_EDITMSG	ORIG_HEAD	description	info		packed-refs
FETCH_HEAD	REBASE_HEAD	hooks		logs		refs
HEAD		config		index		objects

the files in all caps are like gits variables. Lets look at the one called HEAD we have intereacted with HEAD before when resolving merge conflicts.

cat HEAD 
ref: refs/heads/main

HEAD is a pointer to the currently checked out branch.

git status
fatal: this operation must be run in a work tree

Inside the .git directory git commands do not work.

cd ..

git status
On branch main
Your branch is up to date with 'origin/main'.

nothing to commit, working tree clean

that matches the HEAD as expected. Lets swithc and look agian.

git checkout 2-create-an-about-file
Switched to branch '2-create-an-about-file'
Your branch is up to date with 'origin/2-create-an-about-file'.
git status
On branch 2-create-an-about-file
Your branch is up to date with 'origin/2-create-an-about-file'.

nothing to commit, working tree clean
cat .git/HEAD 
ref: refs/heads/2-create-an-about-file

As expected.

9.8. Branches are pointers#

cat .git/refs/heads/2-create-an-about-file 
57de0cd87ec14926273fd4760b94c0ea6f5b87d3
pwd
/Users/brownsarahm/Documents/inclass/systems/github-in-class-brownsarahm-1
cd .git

pwd
/Users/brownsarahm/Documents/inclass/systems/github-in-class-brownsarahm-1/.git
git status
fatal: this operation must be run in a work tree
cd ..

pwd
/Users/brownsarahm/Documents/inclass/systems/github-in-class-brownsarahm-1
cat .git/refs/heads/2-create-an-about-file 
57de0cd87ec14926273fd4760b94c0ea6f5b87d3
git checkout main
Switched to branch 'main'
Your branch is up to date with 'origin/main'.
cat .git/HEAD 
ref: refs/heads/main
cat .git/refs/heads/main 
4fa9114632f26ec590eec7e91712596085d7c442
git status
On branch main
Your branch is up to date with 'origin/main'.

nothing to commit, working tree clean
git checkout organization
Switched to branch 'organization'
Your branch is behind 'origin/organization' by 3 commits, and can be fast-forwarded.
  (use "git pull" to update your local branch)
cat .git/HEAD 
ref: refs/heads/organization
git checkout main
Switched to branch 'main'
Your branch is up to date with 'origin/main'.
git log
commit 4fa9114632f26ec590eec7e91712596085d7c442 (HEAD -> main, origin/main, origin/HEAD)
Author: Sarah M Brown <brownsarahm@uri.edu>
Date:   Tue Feb 14 12:48:11 2023 -0500

    bug fix

commit 6a2e1cc65204d0c05acc477e7d5e704f989a68dc
Author: Sarah M Brown <brownsarahm@uri.edu>
Date:   Thu Feb 9 13:26:28 2023 -0500

    add jacket

commit 8e2fe11b4ed5ac39b22f680a4c627fd88a6628fd
Author: Sarah Brown <brownsarahm@uri.edu>
Date:   Thu Feb 9 13:22:43 2023 -0500

    Update about.md

commit bcdc409a2e646854230114127ab8ad2f336668db
Merge: cffcf05 56f29ca
Author: Sarah Brown <brownsarahm@uri.edu>
git log
commit 4fa9114632f26ec590eec7e91712596085d7c442 (HEAD -> main, origin/main, origin/HEAD)
Author: Sarah M Brown <brownsarahm@uri.edu>
Date:   Tue Feb 14 12:48:11 2023 -0500

    bug fix

commit 6a2e1cc65204d0c05acc477e7d5e704f989a68dc
Author: Sarah M Brown <brownsarahm@uri.edu>
Date:   Thu Feb 9 13:26:28 2023 -0500

    add jacket

commit 8e2fe11b4ed5ac39b22f680a4c627fd88a6628fd
Author: Sarah Brown <brownsarahm@uri.edu>
Date:   Thu Feb 9 13:22:43 2023 -0500

    Update about.md

commit bcdc409a2e646854230114127ab8ad2f336668db
Merge: cffcf05 56f29ca
Author: Sarah Brown <brownsarahm@uri.edu>
Date:   Thu Feb 9 13:20:59 2023 -0500

    Merge pull request #6 from introcompsys/organization
    
    Organization

commit 56f29cad4c33dc9e5c194e6f774024bca756b6ee (origin/organization)
Merge: 812245d cffcf05
Author: Sarah Brown <brownsarahm@uri.edu>
Date:   Thu Feb 9 13:18:04 2023 -0500

    Merge branch 'main' into organization

commit cffcf05fdee460b85057ae3716ce1f10ac205a22
Author: Sarah M Brown <brownsarahm@uri.edu>
Date:   Thu Feb 9 13:09:30 2023 -0500

    add major

commit f2844b2a9c31f83e589a73c1c1b8bd7696c8cf64
Author: Sarah M Brown <brownsarahm@uri.edu>
Date:   Thu Feb 9 13:04:12 2023 -0500

    update title

commit 812245d1177f889dd3ea2e20da6ac104085d25a3 (organization)
Author: Sarah M Brown <brownsarahm@uri.edu>
Date:   Thu Feb 9 12:59:00 2023 -0500

    start organizing
ls .git
COMMIT_EDITMSG	ORIG_HEAD	description	info		packed-refs
FETCH_HEAD	REBASE_HEAD	hooks		logs		refs
HEAD		config		index		objects
cat .git/config 
[core]
	repositoryformatversion = 0
	filemode = true
	bare = false
	logallrefupdates = true
	ignorecase = true
	precomposeunicode = true
[remote "origin"]
	url = https://github.com/introcompsys/github-in-class-brownsarahm-1.git
	fetch = +refs/heads/*:refs/remotes/origin/*
[branch "main"]
	remote = origin
	merge = refs/heads/main
[branch "2-create-an-about-file"]
	remote = origin
	merge = refs/heads/2-create-an-about-file
[branch "fill-in-about"]
	remote = origin
	merge = refs/heads/fill-in-about
[branch "organization"]
	remote = origin
	merge = refs/heads/organization

9.9. Review today’s class#

  1. Review the notes

  2. Update your kwl chart with what you have learned or new questions

  3. Practice with git log and redirects to write the commit history of your main branch for your kwl chart to a file gitlog.txt and commit that file to your kwl repo.

  4. Read about different workflows in git and describe which one you prefer to work with and why in favorite_git_workflow.md in your kwl repo. Two good places to read from are Git Book and the atlassian Docs

9.10. Prepare for Next Class#

  1. In a gitunderstanding.md list 3-5 items from the following categories (a) things you have had trouble with in git in the past and how they relate to your new understanding (b) things that your understanding has changed based on today’s class © things about git you still have questions about

  2. Follow up on your progress issue and plan for the course

9.11. More Practice#

  1. Review the notes

  2. Update your kwl chart with what you have learned or new questions

  3. Practice with git log and redirects to write the commit history of your main branch for your kwl chart to a file gitlog.txt and commit that file to your kwl repo.

  4. Read about different workflows in git and add responses to the below in a workflows.md in your kwl repo. Two good places to read from are Git Book and the atlassian Docs

  5. Contribute either a cheatsheet item, or additional resource/reference to your group repo.

  6. Complete one peer review of a team mate’s contribution

## Workflow Reflection

1. Why is it important that git can be used with different workflows?
1. Which workflow do you think you would like to work with best and why?
1. Describe a scenario that might make it better for the whole team to use a workflow other than the one you prefer.  

9.12. Experience Report Evidence#

9.13. Questions After Today’s Class#

9.13.1. Is the head file shared across all branches and updated every time we checkout a new branch or does each branch have its own head file that stores its own path?#

The head file is like a variable that git writes to every time it checks out a new branch.

9.13.2. Will checking the commit hash locally and in the remote version of the branch play a role in going back in history if you messed something up?#

That is exactly what we will do next

9.13.3. Can look go directly to the git/refs/main file instead of also looking the /HEAD before?#

Yes, these are both files that we looked at, we can look at them in any order.

9.13.4. Just a little bit more clarification on what commands Porcelain and Plumbing have.#

We’ll use porcelain commands next class, that should help make the definitions more clear.

9.13.5. Are the names dictator and lieutenant really used?#

It’s the name of the workflow, but probably if a team is using it they use other terms like team lead or something.

9.13.6. What is a snapshot?#

A “snapshot” is all of the details of the project (repo) at a given time. The term is derived from photography, a picture (aka snapshot) captures a moment in time.

the git parable uses a story to explain git.

this GitHub blog post might also be helpful.

9.13.7. when I set rebase to true, should i set it back to false?#

Depends if you think you will ever want to not default to true.

9.13.8. How did git come to such prominence?#

It is actually, truly, SO MUCH BETTER than what we had before. It is complicated, but so is every other version control system. versioning is hard no matter how you do it.

In addition to what we discussed today git is extremely fast.

It also helps that git is open source. Notice that git uses an integration manager type workflow.

9.13.9. what is the difference between the HEAD and ORIG_HEAD in the main branch?#

These files are not in the working directory or on any branch. These tell us what branch is currently checked out locally and what reference the origin head branch is.

cat .git/ORIG_HEAD
bb4e0d87b6dc7d6c48e5515f6a52cc05948ca9e3

Notice that this gives a commit directly, not another branch. When we do git status we compare this to the local main to find out if we are up to date or not.

9.13.11. Is there a limit to how many branches that one repo can have?#

No.

9.13.12. Will what we learned today help to correct mistakes we make while using Git locally?#

Yes.

9.13.13. will local commit hashes always match with the git servers?#

Unless there is some hacking going on, yes.