zet

Git Notes

Recipes and such for Git source management system.

Mandatory Git Reading

Different Uses for Git

People approach Git with different needs. I believe it is very important to keep this is mind when helping others learn it. Three fundamental differences for me are as follows:

  1. Publishing written content with Git (just knowledge source)
  2. Sandbox quick-n-dirty projects (sometimes gits fall into this)
  3. Formal source code management

Git Master Levels

  1. No Git at all.
  2. Uses Git behind another script or tool.
  3. Understand content states and basic commands.
  4. Branching. Rebasing. Squashing. Merging. Oh my.

Important Concepts and Observations

kaar One big downside with using tools like GitHub and GitLab
is that a lot of information about the code is getting
lost in PullRequest/MergeRequest. Information that should go into you commit messages. GitHub/GitLab issues and prs and comments are lost and hard to migrate

Individual Learning Plan

Tasks I want to upgrade:

  1. Identify reliable sources of knowledge and training

Resources

See Stuff

Add Stuff

git add .        (current dir only)
git add -A .     (current dir and all subdirs recursively)

Delete Tags

git tag -d <tag>
git push origin -d <tag>

“Oh Shit” Recovery

I staged and need to undo it:

git reset -p .

List All Remote Tags

git ls-remote --tags | pae 's,.+/,,'

Create a “Bare” Repo for Local Backups

Some repos have no business being on GitHub or GitLab, but using the same workflow is nice. I prefer to not even keep this anywhere near my $REPOS directory with everything else.

cd # to get home
mkdir priv
cd priv
git init
git init --bare /media/rwxrob/06CF-482C/priv.git
git remote add bak /media/rwxrob/06CF-482C/priv.git
git push --set-upstream bak master

And can clone it with the pull path.

git clone /media/rwxrob/06CF-482C/priv.git

Show the Exact Staged Content

git diff --cached

WARNING: git diff (for me) is utterly useless. Using --cached shows exactly what is staged (when git diff without it will show nothing.

Change First Commit Message

git rebase -i --root

Change Last (Unpushed) Commit Message

git commit --amend

Change Recent Commit Messages (Besides Last)

Careful on this one. N is how far back.

git rebase -i HEAD~N

Delete a Branch (Including Remote)

git branch -d <name>
git push origin --delete <name>

Change Default Branch for Existing Repo

git branch -m master main
git push -u origin main

Changing Default Branch for New Repos

git config --global init.defaultBranch main

Push and Delete Branch

git push origin :branch-to-delete

This works because the colon separates <from>:<to> and an empty from blows away the destination.

Dangerous Shit

git push mirror # omg, i juse blew away all local branches
git push origin :branch-to-delete # deletes remote branch