Learn Git - Checkout Initial Commit
Baby Git Checkout Initial Commit
In this article, we'll walk through the steps to obtain the initial commit for an open source project.
The first step in this process is to choose a project. This could any open source project that you can find on Github, Bitbucket, or any other tool that allows you to access the code for your chosen project. In this example, we'll use the Baby Git codebase which is stored on BitBucket.
- Access the Bitbucket project for the Baby Git codebase
- Click the
- Copy the command
git clone https://firstname.lastname@example.org/jacobstopak/baby-git.git
- Paste the command into a terminal window run it, which should show the following output:
Cloning into 'baby-git'... remote: Counting objects: 413, done. remote: Compressing objects: 100% (409/409), done. remote: Total 413 (delta 270), reused 0 (delta 0) Receiving objects: 100% (413/413), 146.79 KiB | 662.00 KiB/s, done. Resolving deltas: 100% (270/270), done.
- In terminal, browse into the new baby folder by running
- Run the command
git log --reverse, which will list the commit log in reverse order
- The first commit in this list is the initial commit for the project:
commit e83c5163316f89bfbde7d9ab23ca2e25604af290 Author: Linus Torvalds
Date: Thu Apr 7 15:13:13 2005 -0700
Initial revision of 'git', the information manager from hell
- Copy several characters of the commit ID of the initial commit and run the command
git checkout <commit-id>. In this example it will be
git checkout e83c51633. This will yield the following output:
Note: checking out 'e83c51633'.
You are in 'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may do so (now or later) by using -b with the checkout command again. Example:
git checkout -b
HEAD is now at e83c516 Initial revision of 'git', the information manager from hell
- That's it! You have checked out the initial commit for the project, and can look through the files and folders to learn how it works! This can be done for any project that you can obtain the Git history for.
In this article, we discussed how to checkout the initial commit for any Git repository.
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.