Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GIT - How to make a branch be the same as master

I have a website using git

The setup has the master branch as the live site and a develop branch as the dev domain which is used for testing features before they go live

No work is ever done directly on master or develop, it's always done on feature branches and then merged in to develop for testing, followed by master to go live

My issue is that I have one site which has had a lot of work merged in to the develop branch which is never going to go live

I've been asked to make the develop branch match the master branch to ensure the work that's never going live doesn't affect the testing of other new features that get merged in to develop

I've done a bit of research and from my understanding, I can't use rebase as that's more for updating a branch with commits made since you branched off

The only option that seems to do what I need is to rename the develop branch and then recreate it from master and force a push to update it remotely

Is this my best option? Or is there another way I don't know about? Or maybe rebase is correct but I'm not quite understanding its purpose?

Thanks in advance

like image 337
kinger198 Avatar asked Apr 22 '15 11:04

kinger198


People also ask

Why is my branch called Main instead of master?

GitHub took action based on the Conservancy's suggestion and moved away from the term master when a Git repository is initialized, "We support and encourage projects to switch to branch names that are meaningful and inclusive, and we'll be adding features to Git to make it even easier to use a different default for new ...


1 Answers

If you don't care about preserving develop just checkout develop and reset it to master or main or whatever you/ your team named your default branch.

# make sure the default branch is up to date before you do this
git checkout develop
git reset --hard master # replace with your name if it differs
git push -f # force push the branch

This is often done for an integration branch every morning, so that the nightly integration is always based on master.

like image 138
pmr Avatar answered Oct 21 '22 18:10

pmr