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.

Bruce Bookman
  • 115
  • 1
  • 11
  • 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. – Mark Szymczyk Feb 06 '18 at 19:27

3 Answers3

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.

GordonW
  • 1,020
  • 2
  • 16
  • 36
  • 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 – Naman Vaishnav Sep 05 '18 at 06: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 '19 at 14:40
  • To delete the temp branch: https://stackoverflow.com/a/51488525/10124991 – Rehan Ali Khan Apr 03 '20 at 20:42
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

Rehan Ali Khan
  • 308
  • 4
  • 13
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.

B.Slade
  • 143
  • 1
  • 8