Git is very complicated, in total. You can do... anything.
If you use a subset of Git, it can be quite simple and very useful.
So let's try to keep it simple today.
git init
starts
git status
shows what's new/changed
git add
adds files
git rm
removes them
(or you can rm
and git add .
)
git commit -m "Saved!"
Introduction to some terms, with some basic starter steps
Secret stuff lives in .git/
Everything else is your "work tree", your normal files
mkdir git-test
cd git-test
git init
ls -al
What changes are pending? Sometimes called index, but "staging" is clearer
touch new-file
git status
git add .
git status
If you do git status
and see nothing, you are
clean.
Changed files, new files, deleted files... those all create a dirty tree.
Working directory
Stage
HEAD (of current branch, usually main
)
puts changes from your working directory into the stage
puts original copy from HEAD and overwrites your working copy
red lines are in working directory only
green lines are in stage
puts stuff from stage into HEAD
git commit -m "A helpful message!"
git log
Now let's clone an example repository:
cd ..
git clone https://github.com/uwmadison-chm/bioread
cd bioread
Different versions, simultaneously
Git stores a directed acyclic graph (DAG)
git branch
git checkout -b newbranch
Naming a particular version, "v1.0.0"
git tag v2.2.0
Every version (state) of the tree has a generated name
git log --oneline
git diff b4a2
git diff v2.1.0
git diff v2.0.0..v2.1.0
A remote is a copy of the repo that we can push and pull changes to and from
(pull
OR fetch
from some central place, then rebase
your work on it)
push
to somewhere
(often Github or similar host)
git branch -m master main
git blame
git log -S
rebase
rebase -i
: interactively rewriting history!