Martin Olsen
Martin Olsen

Reputation: 1925

Reset remote git branch

I have two remote branches in git, master and test. master reflects whatever will be deployed to our production environment next. test is the same, but for our testing environment.

Because of stalled or scrapped projects test could, over time, theoretically accumulate a lot of commits not present in master. How do I avoid this?

I know one solution would be to delete my local and remote test branch. Then create a new one based on master and push that to remote. However this approach forces my colleagues and build/deploy systems to also delete their local branches before pulling a the new one.

Upvotes: 2

Views: 4342

Answers (1)

VonC
VonC

Reputation: 1328522

Another approach, allowing to pull the test branch is to reset the index of test to the one of master, not rewriting the history of test, but adding a new commit which would reflect the same state as master.
That would however leave in test history all the extra commits.

git checkout master
git merge -s ours test # make master believe that everything from test has been
                         merged to master up to this point.
git checkout test
git reset master -- . # reset the index content of test to the index of master
git checkout # reset the working tree of test to its new index
git commit -m "test reset to master"
git merge master # should be trivial merge
git push origin master
git push origin test

Upvotes: 2

Related Questions