Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to overwrite a certain branch with master

I have two branches dev and master. I want my dev branch to be completely overwritten by master branch as I know master is latest. How can I do that using TortoiseGit UI?

I tried to do merge using TortoiseGit but that would result in many conflicts.

Please let me know the answers in Tortoise GIT only as I am only using UI and not familiar with actual GIT commands.

like image 290
Jack Avatar asked Aug 29 '14 03:08

Jack


People also ask

How do I overwrite a branch in github?

Just like git push --force allows overwriting remote branches, git fetch --force (or git pull --force ) allows overwriting local branches. It is always used with source and destination branches mentioned as parameters.

How do I specify a branch as a master?

Choose Team → then Advanced → then Rename branch. Then expand the remote tracking folder. Choose the branch with the wrong name, then click the rename button, rename it to whatever the new name. Choose the new master, then rename it to master.


1 Answers

Disclaimer : this is not a TortoiseGit solution, but a CLI one, I hope it'll help someone anyway.

Since nobody suggested it already, let's also note this quite simple way to do it :

git branch -f dev master

It's a short way to set the first given ref (here : dev) to the same point where the second ref (here : master) is currently pointing to. (As a sidenote, they're not "linked" in any way after this command, and stay independant for all intents and purposes.)

As it rewrites the history of branch dev, if it has a remote counterpart you'll have to push it with force :

git checkout dev
git push -f origin HEAD

In any case, if you happen to have other people working with you on that branch, any of the solutions here are ways to rewrite history so be sure to discuss this with them beforehand!

like image 124
Romain Valeri Avatar answered Oct 01 '22 08:10

Romain Valeri