Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git - move branch "tag" to other commit?

Tags:

git

Since a branch is more or less only a tag, that moves automatically to the new commit, I wonder if I can modify this "tag".

Example:

             master  
A -- B -- C -- D

git checkout master would be the same as git checkout D

Can I change master to point to commit B?

   master
A -- B -- C -- D

git checkout master would now be the same as git checkout B

Use Case

Imagine someone has pushed one single commit to the online repository. When I do git fetch, I get this commit local, but my master branch still points to the commit before, while origin/master points to the new commit. I just want to move the local master branch to the same commit as origin/master points to.

So, I wouldn't have to merge.

Thanks for your help

like image 970
Van Coding Avatar asked Mar 02 '12 15:03

Van Coding


People also ask

How do I move a specific tag in git?

To switch to a commit-like object, including single commits and tags, use git switch --detach <commitish> , where <commitish> is the tag name or commit number.

Can we move tags in git?

By default, git push will not push tags. Tags have to be explicitly passed to git push . To push multiple tags simultaneously pass the --tags option to git push command.

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.


1 Answers

To move the branch Tag to commit B you can do the following:

git branch -f master B

Using git branch instead of git reset --hard even preserves your working directory.

like image 178
knittl Avatar answered Oct 12 '22 17:10

knittl