Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
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.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...