Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reset other branch to current without a checkout

Tags:

git

People also ask

What is the git command to move the branch pointer to a different commit without checkout?

To move the branch pointer of a checked-out branch, one can use the git reset --hard command.

Does git reset change branch?

It can be changed to point to a different branch, without modifying any branch, by git checkout . In the manpage of git reset , the use of HEAD in "reset current HEAD to the specified state" seems to me that git reset switch to another branch as the current branch, similarly to git checkout .

How do I force a branch to update?

Use git push -f to force update the remote branch, overwriting it using the local branch's changes. This operation is necessary anytime your local and remote repository diverge.


Set otherbranch to point at the same commit as currentbranch by running

git branch -f otherbranch currentbranch

The -f (force) option tells git branch yes, I really mean to overwrite any existing otherbranch reference with the new one.

From the documentation:

-f
--force

Reset to if exists already. Without -f git branch refuses to change an existing branch.


The workflows you describe are not equivalent: when you perform reset --hard you lose all the changes in the working tree (you might want to make it reset --soft).

What you need is

git update-ref refs/heads/OtherBranch refs/heads/CurrentBranch

You can sync with this command your branches at any time

$ git push . CurrentBranch:OtherBranch -f

Also without -f it replace this set of commands

$ git checkout OtherBranch
$ git merge CurrentBranch
$ git checkout CurrentBranch

It can be useful when you don't need commit all your files in CurrentBranch and so you can't switch to another branches.