Git ~ Checkout - rohit120582sharma/Documentation GitHub Wiki

Use this to move the HEAD pointer to a specific commit or switch between branches.

This rollbacks any content changes to those of the specific commit and will not make changes to the commit history.

During the normal course of development, the HEAD usually points to master or some other local branch, but checking out a specific commit will put the repo in a "detached HEAD" state. This means you are no longer working on any branch, HEAD no longer points to a branch—it points directly to a commit.

# git checkout <commit-id>
git checkout c8f864d28ff85213a295a5e66af7dcc63e703dbe

In a detached state, any new commits you make will be orphaned when you change branches back to an established branch. Orphaned commits are up for deletion by Git's garbage collector.

To prevent orphaned commits from being garbage collected, we need to ensure we are on a branch.

This makes your Working Directory match the exact state of the c8f864d commit. You can look at files, compile the project, run tests, and even edit files without worrying about losing the current state of the project. Nothing you do in here will be saved in your repository. To continue developing, you need to get back to the “current” state of your project:

git checkout master
⚠️ **GitHub.com Fallback** ⚠️