-1

I'm new to Git, SourceTree, and version control in general so please forgive my ignorance.

I had a project on Github with a couple dozen commits to the master branch, I never made any other branches so there was only commits to the master and nothing else.

Using SourceTree, I pulled down the project and then Checked out an older version of the project intending to only work on that version and discard all of the newer commits.

At this point, the project branches look like this enter image description here So I work on my older version of the project for a little bit and then go to commit my work. The commit goes smoothly but when I go to push my project to the GitHub server it shows this error message enter image description here It says HEAD detached from a hash. What does this mean and how do I fix it? This is the dialog box that I pushed from. enter image description here

Thank you for your time looking at this.

Edit: I'm wanting to push to the master branch, while the duplicate question was wanting to do something else with his detached head.

j76goatboy
  • 405
  • 2
  • 7
  • 16
  • Possible duplicate of [making a git push from a detached head](http://stackoverflow.com/questions/35736116/making-a-git-push-from-a-detached-head) – Scott Weldon Aug 23 '16 at 21:54

1 Answers1

1

You've made commit with detached HEAD that means that you don't have any branch that refers to HEAD, so you not allowed to push it into GitHub. Your commit should be in master.

So what you should do:

0) Open bash and go to the project directory.

1) Stash your uncommitted changes to keep it safe.

git stash

2) Rebase your commits onto master.

git rebase master

3) Resolve conflicts if you have it.

4) Push changes.

git push

5) Get your stashed uncommitted changes.

git stash pop

All information about git you can find in Pro Git

Volen
  • 357
  • 3
  • 8
  • I'm really confused about how to resolve the conflicts I'm getting. The mark up that it is leaving in my conflicted file doesn't make a whole lot of sense right now. – j76goatboy Aug 24 '16 at 00:25
  • It might help you https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging#Basic-Merge-Conflicts – Volen Aug 24 '16 at 00:29
  • Thanks for the resuourse.Just to make sure, I don't want the end result to be my current project merged with the current master branch. The current master branch is messed up and I want my current project to completely override that version. – j76goatboy Aug 24 '16 at 01:17
  • In this case you can use merge strategy git rebase -X ours. That will resolve all conflicts by getting changes from current commit. Also you can reset master to your current commit: git checkout master then git reset [commit hash], after it you can push with force to override remote branch: git push -f. – Volen Aug 24 '16 at 01:30
  • Checking out the master branch and then resetting with the good version hash did not work as intended. The new commit is the master version without any of my changes. – j76goatboy Aug 24 '16 at 02:07