Vibe coding with Claude Code course Β· Module 2: A Next.js project with Claude Code

Git and GitHub with Claude Code: the ship's logbook

12 min read Β·
In this lesson13

Ahoy! Kraken's Call has a hero section and a crew page, and the logbook has its first entries. Today you will steer it the way a real project does: you will read the changes before saving, open a separate branch for a new feature and send the project to GitHub, where a mentor can look at it.

Problem: ten files in a minute

Claude can change ten files in a minute. If you do not save the states that worked, after a failed change you do not know what was there before and you have nothing to return to. There is a second trouble: the whole history lies only on your disk. When the disk refuses to obey, the project is gone, and the mentor has no way to see it.

What you already know and what is new

In lesson 0_6 you met the repository, the commit, the work loop with a checkpoint, Source Control in Cursor and the .gitignore file. Today comes: reviewing changes before a commit, a message that will still tell you something in a week, branches and GitHub. Claude still runs the commands, and you read and approve them: the Claude Code documentation says that Git becomes a conversation.

Two words that are easy to confuse. Git is a program on your computer that keeps the history of the project. GitHub is an internet service that stores a copy of that history and lets you show it to others. Git works without GitHub, and GitHub gets only what you send it from Git.

Request: review before saving

The crew page from the previous lesson waits to be saved. Before it goes into the history, ask Claude for a review:

Request for Claude Code:

Show which files have changed since the last commit and propose a
commit message: the first line up to 50 characters says what, the
second says why. Do not make the commit until I approve the message.

The request separates two steps: first the review and a proposal, then saving with your consent. Without the last sentence Claude could make the commit right away, before you read the changes.

What Claude wrote

Before it writes anything, Claude checks the state of the project. It will run git status, a command that only reads the state of the repository and changes nothing. The result looks like this:

On branch main
Untracked files:
  (use "git add <file>..." to include in what will be committed)
        app/crew/

nothing added to commit but untracked files present (use "git add" to track)

"On branch main" is the branch you are on. "Untracked files" are files Git does not track yet, here the new folder app/crew/. A file that Git already knows and that has changed would stand under the heading "Changes not staged for commit", and Claude would show its changed lines with the git diff command. None of these commands saves anything in the history.

Then comes a proposed message, for example this one:

Crew page with CrewMember and CrewCard types

Crew data described by an interface so the build catches wrong fields.

Before you approve it, open Source Control in Cursor and click each file from the list, just like in lesson 0_6. A new file shows as added in full. You check two things: whether the list has only the files you asked for, and whether their content has nothing foreign in it.

A good commit message

The Git documentation advises starting a message with one short line, at most 50 characters, that summarises the change, then leaving an empty line and adding a longer explanation. The first line becomes the title of the commit, which you will see in every view of the history. Compare two titles of the same change:

update files
Crew page with CrewMember and CrewCard types

From the first you will read nothing in a week: neither which files nor what for. The second says what was created, and the second line of Claude's proposal adds why. The captain's advice: the title says what, the rest says why, and the "how" is visible in the diff, so there is no need to describe it.

An entry in the logbook

When you approve the message, Claude will ask for consent to two commands:

git add app/crew/page.tsx
git commit -m "Crew page with CrewMember and CrewCard types" -m "Crew data described by an interface so the build catches wrong fields."

git add with a file name adds exactly that file to the save and nothing more. git commit -m saves the state as a checkpoint with a message, and the second -m adds a second paragraph of the message. The commit stays on your computer: nothing has gone to the internet yet. When you later write "show the latest commits", Claude will run git log --oneline and show roughly this list:

0b63fee Crew page with CrewMember and CrewCard types
1171d45 Tailwind hero section for Kraken's Call
4e2a9c1 Home page heading: Ahoy, Pirates!
edfa513 Initial commit from Create Next App

Each line is one entry: the short hash of the commit and its title, the newest at the top. The hashes and messages on your machine will differ, but the order should match the lessons you have completed.

What does not go into the repository

Before you send anything to the internet, check what Git will not save. The wizard from lesson 1_2 created a .gitignore file with a ready list. Open it in Cursor; the most important lines are:

/node_modules
/.next/
.env*
*.pem
next-env.d.ts

/node_modules is the hold from lesson 1_1, and /.next/ is the result of the build: you recreate both with one command. The asterisk in .env* means any ending, so Git skips both .env and .env.local with API keys. *.pem are files with keys, and next-env.d.ts is generated by Next.js itself. If you nevertheless see one of these files in Source Control, stop Claude before it saves it.

GitHub: a port for your project

You create the account on github.com yourself. When sending, Git must also prove that it is you, and the GitHub documentation recommends GitHub CLI for that, that is the gh program, or Git Credential Manager. We choose gh, because it will also create the repository with one command, and the Claude Code best practices advise giving the agent command-line tools. Install it following the page cli.github.com and in the second terminal of Cursor, outside the Claude session, log in yourself:

gh auth login

To the question about the protocol choose HTTPS, and to the question whether to authenticate Git with your GitHub credentials answer Y. You do the login, not Claude: these are the keys to your account.

The repository will be public, because at the end of the location you will show the link to the mentor, and that is why .gitignore mattered so much. Return to the Claude session:

Request for Claude Code:

Create a public repository krakens-call on my GitHub account through
gh, set it as origin and push the main branch. Show the command before
you run it, and at the end the result of git remote -v.

Claude will show the command and ask for consent to run it:

gh repo create krakens-call --public --source=. --remote=origin --push

--public makes the repository public (--private makes it private), --source=. points to the current folder, --remote=origin saves the repository under the customary name origin, and --push sends the commits right away. git remote -v will show the address of the repository next to the name origin; open it in the browser and you will see the files of the project and the commits.

Prefer to create the repository in the browser? On github.com click the plus in the top right corner and choose New repository, enter a name, choose the visibility and click Create repository. Do not add a README, a .gitignore file or a license: the GitHub documentation warns that when you push an existing project this leads to errors. Give Claude the address of the repository in the request, and it will propose two commands:

git remote add origin https://github.com/YOUR-LOGIN/krakens-call.git
git push -u origin main

git remote add saves the address under the name origin. git push sends the commits of the main branch, and -u remembers this connection, so later pushes you shorten to git push. The result ends with the line "branch 'main' set up to track 'origin/main'.". You give the address yourself for a reason: auto mode blocks adding a remote repository that you did not name. The data from gh auth login works here too, because gh remembered it for Git as well.

When to agree to git push

git push sends the history outside your computer, and /rewind will not undo that: in lesson 0_6 you saw that a checkpoint remembers only files. In Manual mode Claude will ask for consent. In auto mode a push to the repository you are working in goes through without a question, and among other things a force push is blocked. The captain's advice: stay with Manual until pushing to GitHub becomes a habit. Before you click Yes, check three things:

  • the branch: you are pushing the one you meant to, for example main or a feature branch;
  • the target: origin points to your repository, which git remote -v shows;
  • no force: the command has no --force or -f, because the Git documentation warns that a force push can make the remote repository lose commits.

Branches: a separate trial voyage

A branch is a separate line of history. On the main branch stays the version that works, and a new feature is built next to it, on its own branch. When it works out, you merge it into main; when it does not, you abandon the branch, and main does not even notice. The next section of the page, "How to play", is a good occasion. Write to Claude:

Create a branch feature/how-to-play and switch to it.

Claude will ask for consent to one command:

git switch -c feature/how-to-play

git switch switches branches, and -c first creates a new one; the terminal answers "Switched to a new branch 'feature/how-to-play'". The new branch starts from the place where you are, so the files on disk do not change. Older tutorials write the same as git checkout -b. When switching would destroy unsaved changes, Git refuses, which is why you make a commit before switching.

When the section is ready and checked, Claude will merge the branch into main with the git merge command. In teams, instead, a pull request is opened on GitHub, that is a request to merge a branch with room for code review. You will meet it in later locations. On another computer you download the project with the git clone command and the address of the repository, and you pull new changes from GitHub with the git pull command.

Undoing: three ropes

For undoing you have three ropes, each for a different moment:

  • before a commit: /rewind from lesson 0_6 undoes the changes Claude made in files;
  • one file: git restore app/page.tsx discards the changes in that file that you have not yet added with git add;
  • a pushed commit: git revert with the commit number saves a new commit that reverses the effects of the old one, so the history on GitHub stays untouched.

Two commands erase work with no way back: git reset --hard, which throws away changes not saved in a commit, and git push --force. Auto mode blocks both. When you see either in a request for consent, answer No and ask Claude for a gentler way.

Captain's review

Before every commit and push, check:

  1. Secrets: the diff has no .env file, API keys or .pem files.
  2. Ballast: the list of changes has no node_modules or .next.
  3. The message: the title says what, the second line says why, and it is not "update files".
  4. Branch and target: the commit and the push go to the branch and the repository you meant.

A typical agent mistake: git add . or git add -A, which add everything at once, also a file that happened to lie in the folder, or a commit straight to main when you asked for work on a branch. You will catch both in the request for consent: read what stands after git add, and check in git status which branch you are on.

Next step

From now on you steer every feature with the loop from lesson 0_6, with two additions: reviewing the changes and the message before a commit, and pushing to GitHub after a finished stage. Before you close this location, you will send the mentor the link to the repository. In the editor below waits a cheat sheet to hang above your bunk: the commit loop with the commands Claude runs, and an excerpt of .gitignore from the project.

Remember: the logbook is kept by the crew, but the captain signs it.

Code for this lesson: git-logbook.md
# Kraken's Call logbook

## The loop of one change

1. Source Control list empty: the last good state is saved.
2. Request for Claude Code: goal, place, constraints, check.
3. Review: the diff in Source Control, npm run build, the page in the browser.
4. "Show the changes and propose a commit message. Do not commit without my consent."
5. Commit: the title says what (up to 50 characters), the second line says why.
6. Stage finished? git push, when the branch and the target match.

## Commands that Claude runs

- git status: what has changed (only reads)
- git diff: which lines have changed (only reads)
- git log --oneline: the list of commits (only reads)
- git add app/crew/page.tsx: adds one named file to the save
- git commit -m "what" -m "why": saves a checkpoint with a message
- git switch -c feature/how-to-play: a new branch and a switch to it
- git push -u origin main: the first push of the main branch to GitHub

## I answer No when I see

- git add . or git add -A with files I did not ask for
- git push --force or git push -f
- git reset --hard
- .env, *.pem, node_modules or .next on the list of changes

Spotted a mistake in this lesson?

Check yourself

Answer the questions from this lesson. Pick an answer to see right away whether it is correct.

  1. 1. What does the command 'git commit -m "..."' do?

  2. 2. What is the difference between Git and GitHub?

Hands-on tasks in the game

  • Vertical ordering

    Arrange the steps: from reviewing changes to pushing them to GitHub:

  • Horizontal ordering

    Arrange the command that saves changes with a message:

  1. QuestionQuiz: The git commit command
  2. Put in orderOrdering: From reviewing changes to GitHub
  3. QuestionQuiz: Git vs GitHub
  4. Put in orderOrdering: Commit command with a message

Useful articles