🐙
Git Developer Guide
About
  • Overview
  • Scope of this book
  • Table of Content
  • 🐢Introduction to Version Control
    • What is Version Control?
    • Overview of git and it's benefits
    • Setting up Git on Different Platforms
  • 🍼Git Fundamentals
    • Initialising a new Git repository
    • Understanding the Git Workflow
    • Committing Changes and Writing Good Commit Messages
    • Viewing and Navigating Commit History
    • Git Basics - Practice Scenarios
      • Initialising a Git Repository
      • Committing Changes
      • Exploring Commit History
      • Amending and Undoing Commits
  • 🦕Working With Git
    • What is Git Branch?
    • Creating and Switching Between Branches
    • Merging Branches and Resolving Conflicts
    • Best Practices for Branch Management
    • Git Workflows
    • Git Log
    • Git Stash
    • Working with Git - Practice Scenarios
      • Creating and Switching Between Branches
      • Merging Branches and Resolving Conflicts
      • Branching Strategies in a Team Project
      • Rolling Back to a Previous Version
      • Experimenting with Feature Branches
      • Working with Stash
  • 🤝Working with Remote Repositories
    • Cloning a Repository from Remote
    • Pushing and Pulling Changes to and from Remote Repositories
    • Collaborative Workflows - Forking, Branching, and Pull Requests
    • Resolving Conflicts in a Collaborative Environment
    • Collaborating with Git - Practice Scenarios
      • Cloning a Remote Repository
      • Pushing and Pulling Changes
      • Collaborative Workflow with Forking and Pull Requests
      • Resolving Conflicts in a Pull Request
  • 🏆Advanced Git Features
    • Aliases and Custom Configurations
    • Working with Tags and Releases
    • Rewriting Commit History with Interactive Rebase
    • Utilising Git Hooks for Automation
    • Advanced Git Features - Practice Scenarios
      • Creating Custom Git Aliases
      • Working with Tags and Releases
      • Rewriting Commit History with Interactive Rebase
      • Using Git Hooks for Automated Testing
  • 😎Git in Real-World
    • Managing a Project with Multiple Contributors
    • Integrating Git with Continuous Integration, Continuous Deployment (CI, CD)
    • Versioning Assets with Git LFS (Large File Storage)
    • Deploying a Web Application using Git
    • Git In Real World - Practice Scenarios
      • Managing a Project with Multiple Contributors
      • Integrating Git with CICD Pipelines
      • Versioning Assets with Git LFS
      • Deploying a Web Application using Git
  • Git Troubleshooting
    • Common Mistakes and Pitfalls When Using Git
    • Undoing Changes with Git - Reverting and Resetting
    • Recovering Lost Commits or Branches
    • Dealing with Repository Corruption or Other Issues
  • Git Best Practices and Tips
    • Creating efficient git workflows: writing clean code for faster reviews
    • The importance of clean code in collaborative development
    • Significance of consistent naming conventions & coding Standards
    • Good code documentation for better git workflows
    • Writing meaningful git commit messages
    • Atomic commits in git & it's benefits for software teams
    • Structuring code & managing dependencies for better git workflows
    • Git branching strategies for software teams
  • Conclusion & Next Steps
    • Recap of Key Concepts and Commands
    • Further Resources for Expanding Git Knowledge
    • Encouragement and Tips for Continued Learning and Practice
  • License Considerations
Powered by GitBook
On this page

Was this helpful?

  1. Git Fundamentals
  2. Git Basics - Practice Scenarios

Committing Changes

Committing changes is a fundamental aspect of using Git, as it allows you to save and track the progress of your project.

Scenario

You're a developer working on a new learning management system's backend api and you're about to commit the changes made on your project files. Here's a pattern for such workflow:

Step1 - Initialise a Git Repository:

Before committing changes, you need to initialise a Git repository in your project directory. Open a terminal and navigate to your project's root directory. Use the following command to initialize Git:

git init

Step 2 - Check the Status:

Once the repository is initialised, you can check the status of your files using the command:

git status

It displays information about untracked, modified, and staged files.

Step 3 - Stage Changes:

Staging is the process of preparing files for a commit. To stage changes, use the git add command followed by the file or files you want to stage. For example, to stage a single file:

git add file.txt

To stage multiple files, list them separated by spaces:

git add file1.txt file2.txt

To add all changes in your working directory to the staging area, this command adds both new and modified files. For example:

git add .

Step 4 - Review Changes:

To review the changes you have staged before committing, use the command.

git diff --staged

Step 5 - Commit Changes:

Committing creates a new snapshot of your project with the changes you have staged. Use the git commit command followed by the -m flag and a descriptive message. For example:

git commit -m "Added feature XYZ"

Write meaningful commit messages that describe the purpose of the changes.


Benefits of Making Smaller, Focused Commits

Making smaller, focused commits offers several benefits:

  1. Improved Readability: Smaller commits with focused changes are easier to understand and review. Each commit represents a specific set of changes, making it simpler to track the project's evolution.

  2. Granular Versioning: Smaller commits allow for more granular versioning. If you need to roll back a specific change or introduce a hotfix, it's easier to identify the relevant commit when changes are compartmentalised.

  3. Easier Collaboration: Smaller commits facilitate collaboration within a team. When multiple developers are working on the same project, smaller commits reduce the chances of conflicts and make it easier to merge changes.

  4. Reverting Changes: With smaller commits, reverting a particular change becomes less daunting. If a commit introduces an issue or breaks functionality, it can be rolled back without affecting other unrelated changes.

  5. Better Code Review: Smaller commits enable more effective code reviews. Reviewers can focus on specific changes, providing more targeted feedback and catching potential issues more easily.

It's essential to strike a balance between making commits too small (resulting in a commit history cluttered with numerous tiny changes) and making commits too large (which can make it harder to understand and review changes).

Aim for logical units of change that maintain a clear and concise commit history.

PreviousInitialising a Git RepositoryNextExploring Commit History

Last updated 1 year ago

Was this helpful?

🍼