Git & GitHub / Git Basics
Committing Changes and Tracking Progress
In this tutorial, you'll learn how to commit changes to your Git repository, including staging changes, committing changes, and viewing commit history.
Section overview
5 resourcesIntroduces the fundamental concepts of Git, including version control, commits, and repositories.
1. Introduction
In this tutorial, we will learn how to commit changes to our Git repository. Committing changes is like saving a version of your files in a repository. This becomes a crucial part of version control when working on projects, especially when collaborating with others.
By the end of this tutorial, you will learn:
- How to stage changes
- How to commit changes
- How to view commit history
Prerequisites:
- Basic understanding of Git and GitHub
- Git installed on your machine
2. Step-by-Step Guide
Staging Changes
Staging changes is the first step before committing in Git. It's a way to prepare and organize your changes before committing them.
To stage changes, use the command: git add <filename>
Committing Changes
After staging your changes, the next step is to commit those changes. Committing is the act of packaging your changes and providing a descriptive message of what has been changed.
To commit changes, use the command: git commit -m "your descriptive message"
Viewing Commit History
It's important to keep track of what changes have been made and by whom. Git provides a command to view the history of commits.
To view commit history, use the command: git log
3. Code Examples
- Staging Changes
Let's say you have a file named index.html and you've made some changes. To stage these changes:
git add index.html
- Committing Changes
After staging your changes, you can commit them with a message describing what you did:
git commit -m "Updated title in index.html"
- Viewing Commit History
To view your commit history:
git log
This will display a list of all commits made in that repository, along with details like the author, date, and commit message.
4. Summary
In this tutorial, we've learned how to stage changes, commit them, and view our commit history. These are fundamental skills for version control in Git. We encourage you to practice these commands until you're comfortable with them.
Next steps for learning could include learning how to work with branches, merge changes, and resolve conflicts.
5. Practice Exercises
-
Stage and commit changes in a file named
practice.txt. Write "This is a practice file" in your file and commit it with the message "First commit". -
Make another change in the
practice.txtfile. Modify the text to "This is an updated practice file", then stage and commit the changes with the message "Updated the practice file". -
View your commit history. Can you understand the changes you've made?
Solutions
echo "This is a practice file" >> practice.txt
git add practice.txt
git commit -m "First commit"
echo "This is an updated practice file" > practice.txt
git add practice.txt
git commit -m "Updated the practice file"
git log
You should see two commits: "First commit" and "Updated the practice file".
Keep practicing these steps with different files and changes to get the hang of committing and tracking progress in Git.
Need Help Implementing This?
We build custom systems, plugins, and scalable infrastructure.
Related topics
Keep learning with adjacent tracks.
Popular tools
Helpful utilities for quick tasks.
Latest articles
Fresh insights from the CodiWiki team.
AI in Drug Discovery: Accelerating Medical Breakthroughs
In the rapidly evolving landscape of healthcare and pharmaceuticals, Artificial Intelligence (AI) in drug dis…
Read articleAI in Retail: Personalized Shopping and Inventory Management
In the rapidly evolving retail landscape, the integration of Artificial Intelligence (AI) is revolutionizing …
Read articleAI in Public Safety: Predictive Policing and Crime Prevention
In the realm of public safety, the integration of Artificial Intelligence (AI) stands as a beacon of innovati…
Read articleAI in Mental Health: Assisting with Therapy and Diagnostics
In the realm of mental health, the integration of Artificial Intelligence (AI) stands as a beacon of hope and…
Read articleAI in Legal Compliance: Ensuring Regulatory Adherence
In an era where technology continually reshapes the boundaries of industries, Artificial Intelligence (AI) in…
Read article