Search code examples
gitatlassian-sourcetree

Fix branch confusion in Git using Sourcetree


I have been working and apparently have not been working on a branch, which I did not realize. Now I have a lot of commits and cannot push to the remote branch

enter image description here

When I look at the history of the repo I'm a bit confused. I see the Master branch well down the commit list. Yet the blue line, which I think is supposed to represent the Master branch, continues, but when I try to check out the master it is giving me a warning seen below.

enter image description here

enter image description here

I don't have a lot of branches, this is my first large project so I am really just working on the master branch. I only need the master branch right now. So I don't mind if I cannot reach other branches or whatnot. At this stage, I just need to know my files are in a good state and need to get working again! Thanks for any help you can give in helping me understand what this all means.


Solution

  • Your detached head can actually become a branch. From your current HEAD you can do git switch -c tempbranch. Then merge your temp branch to master, git switch master; git merge tempbranch finally. Clean your workspace with git branch -d tempbranch.

    To summarize the commands:

    git switch -c tempbranch
    git switch master
    git merge tempbranch
    git branch -d tempbranch