6

Using Azure DevOps, there is a repo with valid code being maintained in a secondary branch. However, the master branch is multiple years out of date.

I want to obliterate the contents of master and overwrite it with the contents of the secondary branch.

I understand that mishandling this can cause serious namespaces issues and I would like to avoid that.

What method would you recommend for completely replacing master with a secondary branch in Azure DevOps?

4
  • 3
    Is this a Git repo or a TFVC repo? Mar 6, 2019 at 19:28
  • This is a "TFS GIT" repo. A GIT repo running inside Azure Devops.
    – nuprap
    Mar 7, 2019 at 17:05
  • 1
    If you don't want to keep the files in master anyway, I would just go for the easy way and rename the branches
    – Melissa
    Mar 8, 2019 at 14:10
  • @Melisco - That works for me, but will it cause any longterm issues?
    – nuprap
    Mar 11, 2019 at 13:49

1 Answer 1

8
  1. Clone the repo to your local machine.

    git clone {repo url}

  2. Go to the local repo and move to the secondary branch.

    git checkout {secondary branch}

  3. Copy all the content - Ctrl+A, Ctrl+C.

  4. Move back to master branch.

    git checkout master

  5. Paste the files (and replace existing files) Ctrl+V.

  6. Commit the changes.

    git add .

    git commit -m "update master"

  7. Push the changes to Azure DevOps.

    git push

Now the master branch updated with the content of the secondary branch.

5
  • I was considering this... but since the master branch is stale by several years, will this cause any issues when master is updated with the secondary branch? Based on what I read, I should consider using the -f flag if I chose this method... is that correct?
    – nuprap
    Mar 11, 2019 at 13:48
  • 1
    clone the repo, copy him for backup, try what I suggested, succeed? good. not? try -f :) Mar 11, 2019 at 14:18
  • 2
    Step 3 should be "copy all files except the .git folder to a temp location Step 4 should be "Copy all the files from step 3 from the temp location and paste them over existing files. Changed behaviour in Windows makes this procedure do nothing if you do not use a physical temp location
    – Henrov
    Jun 18, 2021 at 9:17
  • 2
    is this really the best option? only option? because you'd still have all that history of old commits, I would like to take a snapshot in time, before a series of bad commits, and promote that new master.
    – nagates
    Feb 24, 2022 at 15:43
  • @nagates did you find better way to have history of old commits? Jan 17 at 19:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.