Skip to content

Working with Git

← Back to the start

The technical setup leans on Git, and most days the assistant does the Git work for you. This page is for the days you want to look for yourself: what changed, what a branch holds, how to put something back, and what to do when Git says no. Every command here is safe to run unless it says otherwise.

  1. The everyday loop
  2. Looking over a branch before it's merged
  3. Seeing what changed
  4. Putting things back
  5. When Git says no
  6. Working from more than one computer
  7. Files that don't belong in Git
  8. Asking the assistant about Git

The everyday loop

Whether you or the assistant makes the change, it's the same four steps:

git pull --ff-only          # 1. bring down anything new from GitHub
# ... make your changes ...
git add -A                  # 2. pick up everything you changed
git commit -m "Garden: add the spring watering plan"   # 3. save it with a note
git push                    # 4. send it up to GitHub
  • Pull first. Most Git trouble comes from starting work on a copy that's out of date. --ff-only means "only if it's a clean update", so it never combines changes without telling you.
  • One subject per commit. A note that says what changed and why ("Garden: move watering to mornings, the afternoons were too hot") is worth far more later than "updates".
  • git status any time to see what's changed and not yet saved. It never changes anything.

Looking over a branch before it's merged

When the assistant puts a script or a settings change on a branch, it also opens a pull request on GitHub. That's where you look it over.

  • On the website: open the pull request and choose the Files changed tab. Green lines were added, red lines were removed.
  • From the command line, with the GitHub tool (gh):
gh pr list                  # the open pull requests in this repo
gh pr view 12               # the description of pull request 12
gh pr diff 12               # every line it changes
gh pr checkout 12           # switch your copy to that branch, to try it out
git switch main             # and back again afterwards

If it's a script, try its dry run while you're on the branch. When you're happy, say "merge it" to the assistant, or press Merge on GitHub yourself. If you're not, say what to change; the assistant updates the same branch and the same pull request.

Seeing what changed

git log --oneline -20                 # the last 20 saved changes, one line each
git log --since="1 week ago"          # everything from the past week
git log -p -- garden/watering.md      # every change to one file, with the lines
git show 3f2a91c                      # one saved change in full
git diff                              # what you've changed but not saved yet

The short codes like 3f2a91c are each change's name; the first seven characters are enough. On GitHub, every file has a History button that shows the same thing.

Putting things back

Almost nothing in Git is lost for good. Find your situation:

What happened What to run
You changed a file and want the saved version back git restore garden/watering.md
You want a file as it was in an earlier change git restore --source=3f2a91c garden/watering.md
You saved a change but haven't pushed it, and want to redo it git reset --soft HEAD~1 (your edits stay; only the save is undone)
A change is already on GitHub and was a mistake git revert 3f2a91c, then git push. This adds a new change that undoes the old one, so the history stays honest.
A merged pull request was a mistake On GitHub, open the pull request and press Revert. It makes a new pull request that undoes it.
You deleted a file and saved that git restore --source=HEAD~1 garden/watering.md, then save it again
Something you saved has vanished and you can't find it git reflog lists every place your copy has been recently, even ones no branch points to now. Ask the assistant to help you read it.

Two commands to be careful with: git reset --hard and git clean throw away changes you haven't saved, and those really are gone. Ask the assistant before using either.

When Git says no

"Your branch and 'origin/main' have diverged." Something was saved on another computer (or by the assistant) that you don't have, and you have something it doesn't. Run git pull --rebase to put your changes on top of the new ones. If that stops with a conflict, see the next one.

A merge conflict. Two changes touched the same lines, and Git wants you to choose. The file will have a section like this:

<<<<<<< HEAD
Water in the morning.
=======
Water in the evening.
>>>>>>> 3f2a91c

Keep the line you want, delete the three marker lines, save, then git add the file and carry on with git rebase --continue or git commit, whichever Git suggests. If it's more than a line or two, ask the assistant to explain both sides first. And if you'd rather not deal with it now, git rebase --abort or git merge --abort puts everything back as it was.

"Updates were rejected because the remote contains work that you do not have." Someone pushed first. Pull, then push again. Never answer this with a force push.

"You are in 'detached HEAD' state." You're looking at an old version rather than a branch. Nothing's wrong, and git switch main takes you back.

"Permission denied" or "Repository not found." Either the repo's name is wrong or your login can't see it. gh auth status shows who you're signed in as.

Working from more than one computer

  • Pull before you start, every time, or run sync.sh from the index repo to bring every repo up to date at once.
  • Push when you stop, even if the work isn't finished. Put it on a branch if it's not ready for main.
  • Each computer has its own settings files. The ignored config files and the .claude/settings.local.json file don't travel with the repo, so each computer keeps its own. The config.example file shows what each one needs.
  • A small device can take one folder with Git's sparse checkout, rather than the whole repo:
git clone --filter=blob:none --sparse https://github.com/<your-account>/house.git
cd house
git sparse-checkout set manuals

Files that don't belong in Git

Git is built for text files that change a little at a time. Some things are better kept elsewhere:

  • Passwords, keys and tokens, never. Keep them in a password manager or an ignored settings file. The secret check catches the common slips.
  • Large files that change often, like videos, big photo collections or disk images. Each version is kept forever, so the repo grows quickly. Keep them in ordinary cloud storage and put a note in the repo saying where they are. If you do need them in Git, look at Git LFS (Large File Storage), which keeps the big files to one side.
  • Things a program makes, like a built website or downloaded packages. Keep the recipe in Git and let the program make the rest.
  • Other people's private details. The rules file already says so; the .gitignore file makes it stick. A few lines that suit most repos:
# Settings that stay on this computer
config
*.local.*
.claude/settings.local.json
.env

# Things programs make
site/
node_modules/
__pycache__/
.DS_Store

Asking the assistant about Git

You don't need to remember any of the commands above. These prompts work well:

  • "What changed in this repo this week? Plain English, one line per change."
  • "I want garden/watering.md back the way it was before Tuesday. Show me what that would change before you do it."
  • "Git says my branch has diverged. Explain what's different on each side, and don't change anything yet."
  • "Walk me through pull request 12 file by file, and tell me anything you'd question."
  • "Teach me the one Git command I'd need for this, rather than doing it for me."

← Back: The technical setup · Next: Scripts and automation → · Back to the start