Is it possible to reset a remote branch to another remote branch?
Let's say I have two branches: master
and develop
. The develop
branch is made from master
and used as an integration/build branch. It serves no other purpose.
At the end of a sprint all feature branches, which are approved, are merged into master.
At the end of the sprint, everyone is required to delete his local copy of the develop branch, we delete the remote one, and a new one is made from master. This is not ideal, but the strategy we use itself is the one we agreed upon and bests suits or needs. It's loosely based on the branch-per-feature strategy.
The problem is that, if someone doesn't delete his local copy, and performs an update, he gets the message that his local develop branch is ahead of the remote one. This is because feature branches which were merged in from the previous sprint but did not make it into master are still on his local copy. The build infrastructure itself is also at risk, because if we don't perform a fully clean checkout we risk old stuff still being present.
Actions like reset --hard
don't work, they might reset my local copy, but I'm not able to push these through to the remote branch.
Is there a way to make the develop branch completely identical to the master branch using commits, rather than recreating it?
Update your local version to the commit you want and then force push it to your remote repository:
So, your branches are
master
anddevelop
. You want to resetdevelop
back tomaster
:Or, if you've already deleted the local branch
develop
, you can do it in one step:This pushes the local branch
master
, but names itdevelop
on the remote.The
-f
or--force
flag means "Yes, Git, I'm trying to delete data. I know what I'm doing." In this case, pushingdevelop
would lose the remote commits, but you use-f
to tell Git that you want to lose those commits. Never use-f
unless you know why.