Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in DevOps and Agile by (19.4k points)

To move the branch pointer of a checked-out branch, one can use the git reset --hard command. But how to move the branch pointer of a not-checked out branch to point at a different commit (keeping all other stuff like a tracked remote branch)?

1 Answer

0 votes
by (27.5k points)

In case if you just want to move a branch to another commit:

$ git branch -f branch-name new-tip-commit

In order to move a branch pointer:

$ git update-ref -m "reset: Reset <branch> to <new commit>" refs/heads/<branch> <commit>

The general form:

$ git update-ref -m "reset: Reset <branch> to <new commit>" <ref> <commit>

For more git commands, you can visit the git tutorial.

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94k users

Browse Categories

...