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:
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
To fix this issue, run git pull on your local repository. This should allow you to push to origin again.
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 > !
Just use the small drop-down menu in "Push Commits" window, elevated from VCS -> Git -> Push... or Ctrl + Shift + K .
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.
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.
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)
after that you can Git > Push without problem.
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With