Skip to main content
  1. Learn
  2. Software Development
  3. Guides
  4. Git tutorial
  5. Git basics
  6. Recording changes
  7. Committing changes
GuidesSoftware DevelopmentBacklog
Git

Project and code management together.

Committing changes

Committing changes in Git involves recording the current state of your files in the repository. Each commit creates a snapshot of changes made to the files since the last commit, capturing the project at a specific moment in time to create a point in history that can be referenced, reverted to, or compared with other commits. A unique 40-character checksum hash identifies each commit.

Each commit is accompanied by a commit message summarizing the changes made.

The git commit command lets you record file changes in the repository’s Git history.

Git committing changes
The commit history is stored in the local repository.
Separating different types of changes — such as bug fixes, new features, and improvements — into distinct commits makes it easier for you and your team to understand the purpose and context of each change.

Best practices for committing changes

  1. Commit small, logical units:

    • Break down changes into smaller, cohesive units that focus on one task or fix.
    • Avoid combining unrelated changes in a single commit, as it complicates reviewing and understanding.
  2. Commit frequently:

    • Commit changes regularly as you achieve logical milestones or complete individual tasks.
    • This practice ensures that each commit represents a manageable and coherent set of changes.
  3. Review changes before committing:

    • Use the git status command to review which files have been modified, added, or deleted.
    • Use the git diff command to see the exact changes within files before staging them for commit.
  4. Stage changes selectively:

    • Use git add -p to stage changes interactively, allowing you to commit only portions of a file.
    • This approach helps keep commits focused and avoids unnecessary changes being included.
  5. Avoid committing large files or binaries:

    • Git is optimized for text-based files, and large binaries can bloat the repository size and slow down operations.
    • Use “.gitignore” to exclude unnecessary files (e.g., build artifacts, IDE-specific files) from version control.
  6. Use branches for feature development:

    • Create feature branches to isolate work on new features or experimental changes.
    • Merge branches into the main branch once changes are tested and complete.

Committing changes in Git is fundamental to maintaining a well-structured and manageable version history. By following best practices, you enhance collaboration, traceability, and overall project management efficiency. This approach ensures that your Git repository remains organized, facilitating smoother development workflows and easier maintenance over time.

Subscribe to our newsletter

Learn with Nulab to bring your best ideas to life