Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio Git Push Rejected

I'm trying to uploading my Android Project on github but I get this error when I try to push:

Push rejected: Push to origin/master was rejected

I made this steps:

  • VCS->Import into version control->Create new repository...
  • From the git bash in Project folder:

    git remote add origin https://github.com/[username]/[project_name].git

  • Git->Add

  • Git-> Commit directory

  • Git-> Push

like image 421
Cosimo Sguanci Avatar asked Oct 19 '16 21:10

Cosimo Sguanci


People also ask

How do I fix push rejection?

To fix this issue, run git pull on your local repository. This should allow you to push to origin again.

Why is Github rejecting my push?

Sometimes, Git can't make your change to a remote repository without losing commits. When this happens, your push is refused. If another person has pushed to the same branch as you, Git won't be able to push your changes: $ git push origin main > To https://github.com/USERNAME/REPOSITORY.git > !

How to do force push in Android Studio?

Just use the small drop-down menu in "Push Commits" window, elevated from VCS -> Git -> Push... or Ctrl + Shift + K .

What does git push origin master do?

Git Push Origin pushes all the branches to the main branch. Git Push Origin Master pushes your master branch to the origin. Behavior could be changed via git config. Behaviour is by default.


3 Answers

after push follow these,

VCS --> Git --> Branches

then select origin/master --> Rebase

after finish rebase successful message, you could able to push to remote directory. Hope this helps you.

like image 78
Narendhran Avatar answered Oct 23 '22 21:10

Narendhran


As suggested in the comments you should pull the changes first, if you are working on a new repository that could happened when you create your remote repo with a readme or a licence file. To pull the changes from the user interface you should use, VCS > Git > Pull then select the master branch (depends)

enter image description here

after that you can Git > Push without problem.

like image 93
SamTh3D3v Avatar answered Oct 23 '22 21:10

SamTh3D3v


Just go to the root directory of your project and follow below steps:

  • Right Click-> Git Bash Here

  • Type git init (For initializing git).

  • Type git add -A (Get all files in the staging area).

  • Type git commit -m "First Commit"(Commit Changes)

  • Type git remote add origin https://your_git_url.git (Your repo URL)

  • Type git push -u origin master(master - Branch name)

    OR

  • Type git push -f origin master(master - Branch name) (-f for Force push and make sure there are no changes in your branch to push code.)

You can also make use of Git GUI client:

  • Github Desktop for github users Download
  • GitKracken for Windows, Mac and Linux Download (Free for public repositories)
  • SourceTree for Windows and Mac Download
like image 16
Sumit Shukla Avatar answered Oct 23 '22 23:10

Sumit Shukla