Git Workflow

Git has a workflow that can be a little confusing for new developers, and it works like this.

When a new file is created in a directory that has been initialized with a Git repository, that file will be marked by Git as untracked. This means there is a new file that Git does not have in its history. To start versioning the file is a two-step process.

The first step is to add the file to the staging area. The staging area is where we put files that are ready for Git to commit. The staging area is important in the Git workflow because it allows us to commit some files, but not others, because only the files that are in the staging area will be committed.

After moving files to the stage area, they can be committed. Committing a file is like taking a snapshot of the file at that precise moment. It can then be quickly retrieved in the future, even if further changes have been made. You can think of committing like saving. The more often you commit, the more tracking of the file progress Git will store.

If a change is made to an existing file tracked by Git, it will be marked as modified. Modified files require the same process of adding the file to the staging area and committing the changes.

# stage the newly added or modified file
git stage about.html

# commit the changes with a message
git commit -m 'Adds about page.'