3

pushing to github was working fine. I think this problem started when i checked out a branch from github. How do i fix this? When i try to push to github now, i get the error "The current branch could not be determined."

Also, all my local commits do not show up with comments in either of my local branches. at least not in xcode 9 UI. I don't really know how to use the local git to check these things, so if someone wants to point me to documentation that would be helpful too.

1
  • Can you upload a screenshot of your source control navigator that shows all the branches? That would show what Xcode considers the current branch. Are you able to checkout a local branch by selecting it, right-clicking, and choosing Checkout? How did you check out a branch from GitHub? Updating your question with all that information will make it easier for people to help you here. Feb 6, 2018 at 19:27

3 Answers 3

21

I had this issue, you need to get down and dirty in Terminal :)

The issue is most likely a detached HEAD

This recovery is based on you have made changes whilst head detached and you want to keep these changes.

Navigate to your project directory and execute: git status

If you have a HEAD detached message then:

  • Commit changes: git commit -a -m "you commit comment here"
  • Create a local temp branch: git branch temp
  • Check out the previous branch (the branch you want to use i.e. master): git checkout master
  • now merge your recent changes (from the temp branch): git merge temp

Your all done, go back into Xcode and your back on your branch and everything as you left it :)

Hope this helps.

3
  • Thanks, during checkout master i've got "pathspec 'master' did not match any file(s) known to git." Simply execute git pull solve my problem Sep 5, 2018 at 6:39
  • 1
    This was exactly what I needed, might be worth mentioning that the 'temp' branch can probably be deleted afterwards. Also doing this with Xcode open upset Xcode - had to close and reopen
    – SimonMoss
    Jan 21, 2019 at 14:40
  • To delete the temp branch: i.stack.imgur.com/Lbd5h.png Aug 13, 2022 at 9:29
3

Type these commands (1-4) sequentially in your Command Prompt :

  1. git commit -a -m "you commit message here"
  2. git branch temporary
  3. git checkout master
  4. git merge temporary

Now head over to source control navigator pane in your Xcode project and delete the "temporary" branch from Branches Tab

Source Control navigator pane image

1

I had the same issue after checking out a previous commit and have found a fix.

In Xcode go to Source Control > Clone > Clone the repository you are trying to push and save it, then delete your old Xcode project and replace it with the cloned project and it should work as normal.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

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

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