Staging multiple files
I want to commit all changes made to the repository through a single commit command. However, index.html
, style.css
, and script.js
are not yet staged for changes. Therefore, I must explicitly add them using the git add
command. (Don't run the command on your computer, not yet!)
git add index.html style.css script.js
Alternatively, we can use the following command (wildcard notion): (Don't run the command on your computer, not yet!)
git add .
The git add .
will add all changed and untracked files to the staging area (to be committed). Be careful with this command! It will add "all" files, including those you probably don't intend to include (such as system files), to your Git repository. To avoid this, we will supply a .gitignore
file first.
The .gitignore
file
A .gitignore
file specifies intentionally untracked files that Git should ignore.
Create a file named .gitignore
in better-sleeptime
folder (notice the leading dot). I am going to add the following content to this file
.DS_Store
__MACOSX
My computer is a MacBook; the macOS generates system files .DS_Store
and __MACOSX
, which are typically hidden (so you will not see them by default, but Git will see and track them unless you tell it not to).
You can use this online tool to generate gitignore for different operating systems, project environments, etc.
Let's commit the .gitignore
to our repository: (Now run the command on your computer!)
git add .gitignore
git commit -m "Add gitignore"
git add .
Now, we add and commit the changes made to our project earlier!
git add .
git commit -m "Copy sleeptime app files from previous lesson"