← Back to Git & GitHub

04. Git Workflow

Working Directory & Staging

#1Working Directory & Staging

Now that we've connected our local & remote repos, let's turning the project folder into the local repo.

The two main Git commands that we will use are git add and git commit.

But first, we have to make a distinction between the working directory and the staging area:

- šŸ’» Working directory is the project folder on your computer! When you make changes to the files, Git tracks them, and you can move selected changes to the staging area using the git add command. - šŸ“‹ Staging area is where we prep changes, like "I'm almost ready! One more min!" It's a temporary area where you choose what files you want to "commit" to the local repo with git commit.

#2Git Add

The git add command tells Git which changes you want to include in the next commit. Think of it like packing your suitcase before a trip – it's choosing what to bring.

Here are three variations:

1ļøāƒ£ Add one file: git add example.txt

šŸ”” Add all files: git add .

*ļøāƒ£ Add files with specific extension: git add *.html

bash
git add .

#4Git Commit

Committing files are about saving a "snapshot" of the current code. Each commit captures a moment in time and includes a helpful message to explain what changed. This helps you track your progress and separate different actions in your code.

Now that we are ready to commit your staged files, use the following command:

bash
git commit -m 'Your commit message here!'

#6Understanding Commits

The lowercase -m flag means "message".

Here's what some commit messages might look like for a typical project: - 'Initial commit' - 'Add pics to homepage' - 'Fixed again fr this time!!'

Note: Commit messages get silly when you're working on your own for a while, but short, clear, and descriptive messages are needed when working on a team! We want messages to help you (and your team) understand what changed and why.

If the commit is successful, you should see a message appear in the terminal like: [main 09f4acd] Updated index.html with a new line 1 file changed, 1 insertion(+)