Android Studio Git Push Rejected

Solution 1:

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.

Solution 2:

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.

Solution 3:

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

Solution 4:

For Android Studio if your "Push" is rejected, go ahead and try this:

Try to Pull.(Origin/Master).Right after that:

VCS-->Git-->Branches..-->Remote Branches(origin/master)-->Rebase Current onto Selected

enter image description here

This will eradicate all your contradicting configurations.

Solution 5:

Try this

This type of error was also coming in my project because i have create a new project and paste my old config and some classes file in new project.

I have pushed the code by creating new branch

Go to VCS->Git->Branches->New Branch