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
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.
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.
To move the branch pointer of a checked-out branch, one can use the git reset --hard command.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With