I typed git push -u origin master and got an error saying rejected. How do I fix it?

Veronica Chiaravalli January 20, 2022

Hi,

I typed git remote add origin.... (and my https to the repository)

Then I typed git push -u origin master

I got an error saying rejected. I attach the snapshot.

How can I fix this? 

Thank you.

Best regards,

Veronicanew-error-cannot-push-to-my-repo.jpg

1 answer

1 accepted

1 vote
Answer accepted
Vishwas
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 20, 2022

Hey @Veronica Chiaravalli 

Welcome to Atlassian Community !!

From the error i could see that the remote changes are way forward(means there are already changes pushed to remote and your local is outdated). To fix this you can take a git fetch from remote and then push the code.

Regards,

Vishwas

Veronica Chiaravalli January 20, 2022

Hi Vishwas,

Thank you. 

How do I do that? I am a beginner.

Regards,

Veronica

Vishwas
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 20, 2022

Hey 

Not a problem,  I will guide you.

My guess you are doing commands to do git operations ?

just run this command:

git fetch

and then

git push -u origin master

 

Let me know in case of any issues.

 

Regards,

Vishwas

Like Veronica Chiaravalli likes this
Veronica Chiaravalli January 20, 2022

Hi, 

I did it and I still got an error.

After the git fetch it gave some info.

Then I did the git push -u origin master and got this:

last-error-message-after-git-fetch-and-git-push.jpg

Veronica Chiaravalli January 21, 2022

Hi,

I am still stuck and unable to push the files to my repo.

The only difference is that the error message changed.

Could you please help me?

 

Thank you very much.

Kind regards,

Veronica Chiaravalli

Vishwas
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 21, 2022

Hey,

I guess this is not allowing with just a fetch command we have to run git pull and then run git push.

As mentioned in this article https://stackoverflow.com/questions/57664991/bitbucket-error-failed-to-push-some-refs#:~:text=This%20is%20usually%20caused%20by,push%20%2D%2Dhelp'%20for%20details.

You may have to run this command:

git pull origin master --allow-unrelated-histories

Please check this out, let me know any issues.

Regards,

Vishwas

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events