I need to fix a Git repository that has a detached head and 2 consecutive branches with unrelated histories. I have to use SourceTree at work, but I can use command lines too if needed. What I have to do is to reconcile the current [Head] (3 on the image) with the [origin/master][origin/head][master] (2) without loosing the commits in between. I would also like to merge (or re-attach) the 2 branches (pink and blue). (I only want 1 branch in total). I am not sure in which order it would be best to proceed: reconciling the [Head] and [origin/master] or re-attaching the 2 branches.
I had to hide all the names and comments as this is for work and the content I am allowed sharing is restricted. And sorry if this question is not up to the best standards, it is my first question on any kind of forum.