0

I linked my project with Github 4 months ago and I today deleted my project unintentionally so I reinstall the last commit from Github and open it in Android Studio but when I make any changes I cannot push it to Github as a master branch but if I push it as different branch it is worked, How can I push the changes as the master branch (default)?

enter image description here

Show details in console

12:48:16.974: [Project] git -c credential.helper= -c core.quotepath=false -c log.showSignature=false push --progress --porcelain origin refs/heads/master:master --set-upstream
error: failed to push some refs to 'https://github.com/.../...'
hint: Updates were rejected because the remote contains work that you do
To https://github.com/.../...
!   refs/heads/master:refs/heads/master [rejected] (fetch first)
hint: not have locally. This is usually caused by another repository pushing
Done
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.
Taha Sami
  • 1,565
  • 1
  • 16
  • 43
  • Find out *why* the push was rejected (see the label "Show details in console" in your image). – torek Dec 26 '21 at 10:45
  • @DrHowdyDoo I know what is the problem but I don't know how can I solve it, The problem is that Github thinks I'm not the owner of the project so it permits me to create my branch only but how can I tell Github I'm the project owner even I can update master branch? I saw the link before but does not work with me. – Taha Sami Dec 26 '21 at 10:46
  • @SwissCodeMen I saw the link before but does not work with me. – Taha Sami Dec 26 '21 at 10:46
  • @torek Check the update – Taha Sami Dec 26 '21 at 10:50

2 Answers2

2

You can try git push from console it will either work without issue or it will tell you what exact problem is and the alternate command (something like git push --set-upstream) to fix it.

PS try to learn git basics from any place (youtube / pluralsight) etc and try to use command line as much as you can I have switched to command line for past 2 years and my git understanding is quite improved plus it helps avoid any pesky issues with studio.

Edit - As pointed by the update in question you need to pull the lastest changes by git pull before you can push.

Taranmeet Singh
  • 1,199
  • 1
  • 11
  • 14
1

Select master as your remote branch in Android Studio>Git>Branches>Remote Branches

Tohedul
  • 29
  • 1
  • 7
  • I selected the master branch already, Check the image above – Taha Sami Dec 26 '21 at 10:13
  • 1
    There might be two reasons: 1. You have the wrong remote URL set. 2. Your PC's ssh key expired or didn't add in your git setting ssh list. – Tohedul Dec 26 '21 at 10:40
  • I know what is the problem but I don't know how can I solve it, The problem is that Github thinks I'm not the owner of the project so it permits me to create my branch only but how can I tell Github I'm the project owner even I can update master branch? – Taha Sami Dec 26 '21 at 10:52