What actually is git?
Contents
7. What actually is git?¶
7.1. Grading Contract Q & A¶
Grading contract information is added to the syllabus
and the FAQ section
7.2. Git is a File System with a Version Control user interface¶
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
7.3. Git is distributed¶
Git can have different workflows
7.4. What are the parts of git?¶
and we’re going to start by examinging our familiar github inclass repo
cd path/to/sysinclass/github-in-class-brownsarahm/
ls -a
. .github README.md b_file setup.py
.. CONTRIBUTING.md a_file docs test_file.md
.git LICENSE.md about.md mymodule tests
We are going to look inside the git folder
cd .git
ls
COMMIT_EDITMSG description info packed-refs
HEAD hooks logs refs
config index objects
The most important parts:
name |
type |
purpose |
---|---|---|
objects |
directory |
the content for your database |
refs |
directory |
pointers into commit objects in that data (branches, tags, remotes and more) |
HEAD |
file |
points to the branch you currently have checked out |
index |
file |
stores your staging area information. |
7.4.1. Git HEAD¶
We can look at the head file
cat HEAD
we see
ref: refs/heads/main
This tells us where in the git history the current status of the repository is.
This is what git uses when we call git status
. It does more after reading that
file, but that is the first thing it does.
cd ..
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)
a_file
b_file
test_file.md
nothing added to commit but untracked files present (use "git add" to track)
Note that the current branch is main and the HEAD file has a path to a file named
main in the refs
directory.
7.4.2. Git Refs¶
We can loook at that
cat .git/refs/heads/main
we see the most recent commit hash.
cea6a93d576ecd042823fca24553a58a6cd6565b
We can verify this with git log
when we run this it opens the log interactively, so we see something like:
commit cea6a93d576ecd042823fca24553a58a6cd6565b (HEAD -> main, origin/main, origin/HEAD)
Author: Sarah Brown <brownsarahm@uri.edu>
Date: Thu Feb 3 16:42:12 2022 -0500
try to prevernt repeated running
In parenthesis that is what branches are pointed to that commit. Use enter/return
to scroll and press q
to exit.
Try it Yourself
use git log to draw a map that shows where the different branches are relative to one another
cd ..
cd refs/
ls
heads remotes tags
cd heads/
ls
main reset test
this has one directory for each branch. we can confirm this with git branch
at the top level.
cd ..
ls remotes/
origin
cd remotes/origin/
ls
HEAD main reset
(base) brownsarahm@origin $ cat HEAD
ref: refs/remotes/origin/main
(base) brownsarahm@origin $ cd main
-bash: cd: main: Not a directory
(base) brownsarahm@origin $ cat main
c15cf43b6807e172aaba7cf3b57adc7214b91082
(base) brownsarahm@origin $ cd ..
(base) brownsarahm@remotes $ cd ..
cd ..
cat 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.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "main"]
remote = origin
merge = refs/heads/main
[branch "reset"]
remote = origin
merge = refs/heads/reset
ls
COMMIT_EDITMSG config info refs
FETCH_HEAD description logs
HEAD hooks objects
ORIG_HEAD index packed-refs
cat ORIG_HEAD
c15cf43b6807e172aaba7cf3b57adc7214b91082
pwd
/Users/brownsarahm/Documents/sysinclass/github-in-class-brownsarahm/.git
cd ../../
pw
7.4.3. Git Config and branch naming¶
cd .git
cat config
and we see
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
[remote "origin"]
url = https://github.com/introcompsys/github-in-class-brownsarahm.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "main"]
remote = origin
merge = refs/heads/main
[branch "reset"]
remote = origin
merge = refs/heads/reset
This file tracks the different relationships between your local copy and remots that it knows. This repository only knows one remote, named origin, with a url on GitHub. A git repo can have multiple remotes, each with its own name and url.
it also maps each local branch to its corresponding origin and the local place you would merge to when you pull from that remote branch.
Warning
I remoeved looking at the index here, we’re going to come back to it with more time to inspect it more carefully on Thursday
7.5. Starting a Git Repository from Scratch¶
We’ll create clear repo at the top levle of our inclass directory so that it is not inside another repo
cd ..
pwd
/path/to/Documents/sysinclass
then ceate the repo with
git init test
hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint: git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint: git branch -m <name>
Initialized empty Git repository in /Users/brownsarahm/Documents/sysinclass/test/.git/
git branch -m main
fatal: not a git repository (or any of the parent directories): .git
cd test
git branch -m main
and we can confirm it works with
git status
to see that it is now on branch main.
On branch main
No commits yet
nothing to commit (create/copy files and use "git add" to track)
ls
7.6. Prepare for next Class¶
review the notes and ensure that you have a new, empty repository named test with its branch renamed to main from master.
Add the following to your kwl:
|git workflows | _ | _ | _ | | git branches | _ | _ | _ | | bash redirects | _ | _ | _ |
Practice with git log and redirects to write the commit history for your kwl chart to a file
gitlog.txt
and commit that file to your repo.
7.7. More Practice¶
Read about different workflows in git and add responses to the below in a
workflows.md
in your kwl repo. Git Book atlassian DocsContribute either a glossary term, cheatsheet item, additional resource/reference, or history sidebar to the course website.
## Workflow Reflection
1. What advantages might it provide 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.
7.8. Questions after class¶
7.8.1. when should the grading contract be turned in?¶
First draft is due Thursday, Feb 17 at 4pm as in the README
7.8.2. Can you create multiple remotes that have the same name?¶
no each remote has to have a different name, like each variable in a program has to be unique if you try to create a new remote with the same name it would overwrite the old one
7.8.3. what does it mean when a branch is both x commits ahead of main, but also y commits behind?¶
that means that there have been y commits to main that are not included on the other branch and that there are x commits to the other branch that are not on main.
7.8.4. Should we be working with Git entirely from the terminal for classwork or is it our preference?¶
In class, we will use the terminal because it is the most consistent and transparent. For other work, you can edit it however you like. You can work in browser, with the GitHub desktop client, using the GitHub CLI, or your favorite IDE’s tools. I recommend giving the terminal a serious try because it will have all of the features of git and other tools may not, but your preference is fine. It could actually be really good for your general understanding to practice with git at least two ways.
7.8.5. Will we be using the github cli to publish our repo to github?¶
We are going to mostly use the base git CLI because it is more general and usable in more contexts (for example, your remote could be on GitLab or BitBucket or an internal private server)
7.8.6. Questions we will answer in the next couple of classes¶
What is the purpose of the index file?
How do you add your local repo to github?
What would happen if we would change this hexadecimal code which is in the files in .git?
Are any more efficient ways to navigate through repositories and git files