My master GIT branch seams to have some errors thus I'd like to recheck, re-merge or possibly clone my dev branch over the master branch so the master branch would be a copy of dev.
How can I do that? Thx.
If the problem is simply that your checked-out files don't match up with the branch, just use git reset
normally:
git reset --hard HEAD
That should be all you need. However, if you still want to overwrite master with dev, read on.
If you want to overwrite your master branch with the contents of your dev branch, use git reset
like so:
$ git checkout master
$ git reset --hard dev
And then if you want to push this somewhere else:
$ git push origin master
Note that if your dev branch doesn't fast-forward from your master branch (which I'm guessing it won't, since you said that your master branch has some screwed up stuff in it), you'll need to add the --force
flag to the push to overwrite it on a remote:
$ git push origin master --force
Note, however, that this can involve all of the normal caveats of rewriting history a la git rebase
- if anyone else uses this remote, they'll need to deal with the equivalent of an upstream rebase.
To avoid this problem in the future, advise your friend that using --force
is almost never necessary. If they're getting conflicts when they try to git push
, they should git pull
first, resolve the conflicts, and then git push
.