Wasteland
Wasteland

Reputation: 5379

git - remove the files in a remote branch and sync with another branch

There are a few branches branches (master, test1, test2,)

I have just cloned the whole repository and would like to 'sync' test1 and test2 branches. Remotely, test1 has the desired content, test2 is out of date. I would like to:

  1. remove the files in the test2 branch (both locally and remotely)
  2. sync/merge test2 with test1 so that test2 has the same contents as test1 deleting the current content of test2.

So in other words how would I pull the contents of test1 and put it in test2 (destroying all the current content of test2).

Upvotes: 0

Views: 3355

Answers (1)

Chowlett
Chowlett

Reputation: 46667

I'd probably do:

git branch -d test2   # Delete test2 locally
git checkout test1
git checkout -b test2 # Recreate test2 locally from test1
git push -f           # Forcibly bring remote test2 into step

But do remember the usual caveat; if other people have the upstream test2, then overwriting its history is not very friendly.

Upvotes: 2

Related Questions