Save my changes: commit and push

safe beginner #commit#push#add#daily

When to use this: You edited some files and want them saved in Git and on GitHub (which triggers a Vercel deploy).

Before you start

Steps

  1. See what changed

    terminal
    git status -sb

    Lists changed files. M = modified, ?? = new and untracked. The first line shows if you are ahead or behind the remote.

    Expected output
    ## main...origin/main
     M src/pages/index.astro
    ?? src/content/new-page.md
  2. Stage the changes

    terminal
    git add -A

    Puts all changes in the staging area. To commit only some files, name them: git add src/pages/index.astro.

  3. Commit with a clear message

    terminal
    git commit -m "Add Vercel domain scenario"

    Saves the snapshot locally. Good message: short, present tense, says what and why (Fix broken link on home page). Not update or stuff.

  4. Push to GitHub

    terminal
    git push

    Uploads the commit. If the branch is Vercel's production branch (main), Vercel starts a production deploy automatically; other branches get a preview deploy.

    Expected output
    To https://github.com/you/my-site.git
       3f2a1b9..8c4d7e0  main -> main

How to verify it worked

  • git status says nothing to commit, working tree clean and up to date with 'origin/main'.
  • The commit appears on GitHub, and a new deployment appears in Vercel.

How to undo it

Not pushed yet and want to undo the commit but keep the edits: see 'Undo my last commit'. Already pushed: use a revert commit instead.

Common errors and fixes

rejected ... (fetch first) or non-fast-forward GitHub has commits you do not. Run git pull, then git push again. See the 'push rejected' scenario.
nothing to commit, working tree clean You have no changes, or they are in another folder. Check you saved the files and are in the right repo.
The current branch has no upstream branch Run the command Git suggests: git push --set-upstream origin <branch>.

Q&A

Why stage and commit as two steps?

Staging lets you choose exactly which changes go in a commit, so unrelated edits can become separate, clean commits.

What is git commit -am?

It stages and commits changes to files Git already tracks in one go. It does not include brand-new files, so use git add for those.

Does commit send anything to GitHub?

No. Commit is local. Only git push uploads to GitHub.

Practice these as flashcards →

Terms in this scenario

Related scenarios

My notes

Saved in this browser only.