What is an initial commit in Git?
ADVERTISEMENT
Table of Contents
- Introduction
- Background on Git commits
- What is an initial commit in Git?
- What content should the initial commit contain (if any)?
- Summary
- Next Steps
Introduction
In this article, we will:
- Provide some background on Git commits
- Describe what an initial commit is
- Explain what content an initial commit should contain
Background on Git commits
Git is a Version Control System (VCS) that is used to track the history of software projects. A software project is made up of one or more files that contain code. This code can be written in one or more programming languages, like JavaScript, Python, Java, etc.
Teams of developers edit the code in these files (and create new files) to add new features and functionality to the project. Each developer can independently tell Git to store their changes as they write and edit the code. Each set of changes that Git stores in this way is called a commit.
A new commit is made in Git using the following command:
git commit -m "Descriptive message"
When a developer makes a commit, they have the option of specifying a Git commit message describing the changes in that commit. Git stores this message as a part of the commit, along with the author's name, email address, date, and time of the commit.
commit 4b60f2236009d4a6bc76837f43d95a97ce5612ca (HEAD)
Author: Jacob Stopak <jacob@initialcommit.io>
Date: Mon Jan 24 18:02:27 2020 -0800
Initial commit
Each commit is uniquely identified by a commit ID, which is a long alphanumeric string that can be seen in the example above.
So in a nutshell, a commit in Git represents a labelled set of code changes made by a specific developer at a specific time. As developers collaborate and make more commits, Git chains these together to form a history of development that is very useful for cooperation and tracking over time. This history is called the revision history of the project.
Now that we know what a Git commit is, we'll discuss the term initial commit.
What is an initial commit in Git?
Besides the name of this website, an initial commit is the first commit made in a Git project. As mentioned in the previous section, developers use Git to create chains of commits that track the revision history of a project. Well, each chain has to start somewhere, right?! The first commit that a developer makes when they start a new software project is called the initial commit.
What content should the initial commit contain (if any)?
Even though the initial commit is first in a project, it is still a commit like any other. Therefore, it will definitely contain some content.
But what files should we include as a part of the commit? The answer to this depends on whether the project is brand new or whether it already has a set of code files that we want to use as a starting point.
For brand new projects, there typically aren't yet any code files for Git to track, since the developers haven't written any code yet! In this case, the initial commit usually contains a single file called README.md
which is simply a text file describing the purpose of the project.
For projects that already have some code files written and ready to go, the initial commit usually includes all of those code files in one big chunk. This commit acts as the starting revision for the project in Git. Developers will build off of this to add more features and functionality to the project.
Summary
In this article we provided some background on Git commits, described what an initial commit is, and explained what content an initial commit should contain.
Next Steps
If you're interested in learning more about how Git works under the hood, check out our Baby Git Guidebook for Developers, which dives into Git's code in an accessible way. We wrote it for curious developers to learn how Git works at the code level. To do this we documented the first version of Git's code and discuss it in detail.
We hope you enjoyed this post! Feel free to shoot me an email at jacob@initialcommit.io with any questions or comments.
Final Notes
Recommended product: Decoding Git Guidebook for Developers