Skip to the content.

Making First Commit

Let’s add the README file to the staging area and check the git status. You’ll see README and index.html are staged for commit.

On branch master
No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
        new file:   README
        new file:   index.html

Let’s make our first commit:

# The commit command performs a commit, and the -m "message" adds a message.
git commit -m "making my first commit"

check the status:

git status
# use git log to see the commit details. We will learn more on "git log" a little later in the course
git log

Skipping the staging area

The staging area is amazingly useful for crafting commits exactly how you want them, however, sometimes you have a lot of modified files and you don’t want to add them all one-by-one in the staging area. Sometimes it feels a bit more complex than you need in your workflow.

To skip the staging area, Git provides a simple shortcut. Adding the -a option to the git commit command makes Git automatically stage every file that is already tracked before doing the commit, letting you skip the git add part:

Let’s make changes to README and use -a option to commit it without staging (skipping git add).

echo "Adding a new line to test -a option" >> README
git status
git commit -a -m "skipping the staging area"

📋🎤 Create a new file with some content and name it as NOTES. Try making commit by skipping the staging area and see what happens:

Not sure how? ```shell # creating a new file echo "this file will contain my notes" > NOTES git status # this will not commit git commit -a -m "trying to skip the staging area for a newfile NOTES" git status ``` You will see the NOTES file was not committed. New files have to be added using `git add`. The `-a` option works only with already tracked files.


Lab

In this lab you will create new files and commit the changes to git.

Stuck? Try hints or check the solution.