Git

How do I Make a Branch Point at a Specific Commit in Git?

While working on the development project, developers use multiple branches for testing each feature. Each branch keeps its own commit history. The branch pointer points to the most recent commit. However, sometimes, users want to move the branch pointer to another commit. In this situation, Git commands are available to perform this operation.

This write-up will explain the method to make a branch point at a particular commit in Git.

How to Make a Branch Point at a Specific Commit in Git?

Try out the provided steps to make a branch point at a specific commit in Git.

    • Switch to a local repository.
    • View commit history.
    • Choose the desired commit hash.
    • Move the branch pointer using the “git reset –hard <commit-id>” command.
    • Verify Changes.

Step 1: Redirect to Local Repository

First, utilize the below-listed command and switch to the particular local repository:

cd "C:\Git\Repo1"

 
Step 2: View Git Logs

Then, check the commit history to view the branch pointer:

git log --oneline

 
Here, it can be seen that the “master” branch pointer is currently pointing to the “43e5d18” commit. Now, copy the desired commit id where you want to move your current branch pointer:


Step 3: Move Branch Pointer

Now, execute the provided command along with the selected commit id:

git reset --hard 26a90b4

 

Step 4: Verify Changes

To ensure that the branch pointer is pointing to the specified commit id, run the following command:

git log --oneline

 
As you can see, the HEAD of the “master” branch is now pointing to our desired commit:


We have explained the easiest way to make a branch point at a specific commit.

Conclusion

To make a branch point at a certain commit, first, navigate to the local repository and view its Git log. Then, choose the desired commit id where you want to move your branch pointer. After that, run the “git reset –hard <commit-id>” command and verify changes by viewing the commit history. This write-up explained the method to make a branch point at a particular commit in Git.

About the author

Laiba Younas

I have done bachelors in Computer Science. Being passionate about learning new technologies, I am interested in exploring different programming languages and sharing my experience with the world.