2

I created a new Xcode project and also selected below option:

enter image description here

Then after some coding I went to source control menu and selected commit. After I committed my files, then also my master branch isn't visible

enter image description here

I need to add a remote repository and push this xcode project to github repository.

I have tried all these solutions:

Raywenderlich

Appcoda

All answers from this stackoverflow link too

What could the issue be? I am using git version control for the first time so unable to figure out what's missing.

EDIT Using @VonC Solution:

Getting this error when I push using command line:

 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/xia.....'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

EDIT 2 :

This is what branch I have at my github page:

enter image description here

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Mamta
  • 921
  • 1
  • 10
  • 28

1 Answers1

2

Switch back to the command line to know more:

cd /path/to/my/local/repo
git status

If you see a master branch, check the remote

git remote -v

If you don't see one:

git remote add origin /url/github/empty/repo

git fetch
git branch -u origin/master master
git pull --rebase

git push -u origin master

since master is now associated to origin/master, the next push will simply be a git push.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • The branch master and the remote are proper – Mamta Mar 19 '18 at 05:37
  • @Mamta And the git push? – VonC Mar 19 '18 at 05:38
  • I edited question. Not able to push some refs on push command – Mamta Mar 19 '18 at 05:49
  • @Mamta Do a `git pull --rebase` first, then `git push`. – VonC Mar 19 '18 at 05:50
  • How to do that @VonC? Please give some insights – Mamta Mar 19 '18 at 05:51
  • @Mamta just by typing those two commands from within your local repo in command line. – VonC Mar 19 '18 at 05:52
  • This is what I got on git pull --rebase : There is no tracking information for the current branch. Please specify which branch you want to rebase against. – Mamta Mar 19 '18 at 05:53
  • @Mamta First: `git fetch`, then `git branch -u upstream/master master`, then try again the pull. – VonC Mar 19 '18 at 05:55
  • This is what I get with `git branch -u upstream/master master`: `error: the requested upstream branch 'upstream/master' does not exist hint: hint: If you are planning on basing your work on an upstream hint: branch that already exists at the remote, you may need to hint: run "git fetch" to retrieve it. hint: hint: If you are planning to push out a new local branch that hint: will track its remote counterpart, you may want to use hint: "git push -u" to set the upstream config as you push.` I have master branch at my github page. Check edited question – Mamta Mar 19 '18 at 06:00
  • @Mamta Sorry: `git branch -u origin/master master` (origin, not upstream) – VonC Mar 19 '18 at 06:00
  • that worked!! I can see my xcodeproj on github page now! Thanks alot! – Mamta Mar 19 '18 at 06:03
  • With which commands do I push commit the next time to same repository? I still can't see master branch in my source control menu in xcode – Mamta Mar 19 '18 at 06:06
  • 1
    @Mamta A simple git push will be enough: your local `master` branch is now associated with `origin/master`. – VonC Mar 19 '18 at 07:25
  • Thanks fo all the help @VonC – Mamta Mar 19 '18 at 08:22