GIT

Git Add & Commit

Save changes

Git Add & Commit

Git has three main states that your files can reside in: modified, staged, and committed. The git add command stages files, and git commit saves the changes.

Check Status

First, check the status of your repository:

git status

Add Files to Staging

To stage a file for commit, use git add:

# Add a specific file
git add filename.txt

# Add all files in current directory
git add .

# Add all files in the repository
git add -A

Commit Changes

After staging, commit your changes with a descriptive message:

git commit -m "Add new feature"

Commit Workflow

The typical workflow is:

  1. Make changes to your files
  2. Stage the changes: git add .
  3. Commit the changes: git commit -m "message"

View Commit History

To see your commit history:

git log

Amend Last Commit

If you forgot to add something to your last commit:

git add forgotten-file.txt
git commit --amend -m "Updated commit message"

Tip: Write clear, descriptive commit messages. They help you and others understand what changes were made and why.