AI Hints
Home›Git & GitHub Tutorial›Files In and Out
Git & GitHub · Lesson 20 of 144

The Commit Shortcut

Git commit -am.

⏱ 2 min read▶ Video at 20:21🎓 Free
Watch this lesson in the Git & GitHub courseWatch on YouTube ↗Full Git & GitHub course

When you've only changed files Git already knows about, there's a shortcut. You can stage and commit, in one step.

The Commit Shortcut
From the video: The Commit Shortcut
  • Only changed, known files?
  • Stage and commit in one go
  • git commit -am

Dash a m

We edited two files, the home page and the styles. Instead of git add, then commit, we type git commit dash a m. Dash a means add all changed files that Git already tracks. Dash m is the message. Both files are committed at once.

git
git status --short
 M index.html
 M style.css
git commit -am "Update text and colors"
[main 80ab38a] Update text and colors
 2 files changed, 2 insertions(+), 1 deletion(-)

The catch

But there's a catch. Dash a skips new, untracked files. Here we created a new contact page, and committed with dash a m. Git says nothing added to commit. The new file was left out. For new files, you always need git add first.

git
git commit -am "Add contact page"
On branch main
Untracked files:
  (use "git add <file>..." to include in what will be committed)
        contact.html

nothing added to commit but untracked files present (use "git add" to track)
git status --short
?? contact.html

Summary

git commit dash a m stages and commits changed files in one step, but never new files. Next, your turn to practise everything so far.

Key takeaways
  • git commit -am "message"
  • Only for tracked files
  • New files need git add
Next up: Practice: A Tiny Project — your first full history