Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reset a branch to another branch with git?

Tags:

git

let's say that we have an hotfixes branch which was created from master. we added commits to hotfixes, but those commits were not useful, so now we want to start from a fresh copy of master again.

to clarify better, this is the reference workflow: http://nvie.com/posts/a-successful-git-branching-model/

let's also say that we pushed hotfixes to the origin remote because we have an awful set up and that's the only way to test something, so we need to reset the branch also on the remote server.

how to reset hotfixes to a copy of master?

like image 448
danza Avatar asked Apr 11 '13 07:04

danza


People also ask

Does git reset affect other branches?

(It does not affect the working tree or the current branch.) This means that git reset <pathspec> is the opposite of git add <pathspec> . This command is equivalent to git restore [--source=<tree-ish>] --staged <pathspec>... .


1 Answers

this is how i did it with basic Git commands:

git checkout hotfixes git reset --hard master git push --force origin hotfixes 

of course it's important to notify everyone working on hotfixes. most likely they will have to delete their local copy and start from a fresh one. an alternative, less invasive idea is to create a new branch:

git checkout master git branch -tb hotfixes-2 # this creates branch `hotfixes-2` from a copy of `master` git push origin HEAD # this creates `hotfixes-2` on the remote server 
like image 160
danza Avatar answered Oct 13 '22 11:10

danza