![]() |
Git pros frequently utilize this strong approach to rebase branches, correct errors, and modify branch histories: shifting the branch pointer to a different commit without checking out. With this approach, you can modify the commit that a branch points to without affecting the status of your working directory. When you need to make corrections to the branch history without disrupting your ongoing work, this might be really helpful. Table of Content Approach 1: Using ‘git branch -f’ Command:This is the most simple way to move a branch pointer. The git branch -f command forcefully updates the branch to point to a new commit.
git branch -f <branch-name> <commit-hash>
Example:To move the branch feature to commit 1e50717, run: git branch -f feature 1e50717
![]() Using ‘git branch -f’ Command Approach 2: Using git update-ref CommandThe git update-ref command updates the reference of a branch directly. This method is slightly more low-level than using git branch -f.
git update-ref refs/heads/<branch-name> <commit-hash>
Example:To move the branch feature to commit 1e50717, run: git update-ref refs/heads/abcBranch 069b95e
Output: ![]() Using git update-ref Command |
Reffered: https://www.geeksforgeeks.org
Git |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 22 |