Push failed - your local branch is behind the remote branch

I am so new to Github.
I am trying to push my updated code from Visual Studio 2019.
I already created a repo, so I am trying to push to the same repo.
I got bottom message:


What should I do?

@jdohbeecanhealth When you create a repository, it contains information, even if there are no files in it (which can happen when you initially create a repository). So the reason you’re getting that message is that one of git’s features to ensure you don’t overwrite the remote git history is that it refuses to push from the local to remote if the local doesn’t yet match the remote.

So basically, you’ll need to do a pull before you can push.

That assumes you’ve cloned the repo locally already, and that’s the directory where you have the code you want to push.

Can you confirm the status by using git remote -v and paste the output here please? Also, please paste the output of git log.

1 Like

The message tells you there are commits on the branch in the remote repository (on GitHub) that you’re pushing to that aren’t in your local repository (the ones listed under “incoming”). The push failed because it would overwrite (lose!) those commits, and by default Git refuses to do that.

What to do depends on what you want:

  • If you want to keep both local and remote commits, either merge the remote changes into your local branch, or rebase your local branch on top of the remote one. Then push.
  • If you want to discard the remote commits, force-push. This is a potentially destructive operation, so double check if it’s really what you want. :warning:

I recommend you take a look at the Git - Book, chapter 3 “Git Branching” explains these things in detail.

1 Like

Thanks for help.
Bottom is output.
(I manually tried PULL, but I only got this message, and after I clicked “Output window”, nothing pops up. Where is Output window?)
image

C:\Users\Justin Dolt\source\repos\Sage_0523>git remote -v
origin https://github.com/jdohbeecanhealth/Sage_0523.git (fetch)
origin https://github.com/jdohbeecanhealth/Sage_0523.git (push)

C:\Users\Justin Dolt\source\repos\Sage_0523>git log
commit cd53738ab34b71732e3d23bb51ac96620bcbbfd1 (HEAD → master)
Author: jdohbeecanhealth 106199539+jdohbeecanhealth@users.noreply.github.com
Date: Tue May 31 13:58:30 2022 -0700

test

commit e2bf9f46ae7fbdc0eaec143241b560a2f81300d2
Author: jdohbeecanhealth 106199539+jdohbeecanhealth@users.noreply.github.com
Date: Tue May 31 13:53:30 2022 -0700

Create azure-webapps-dotnet-core1.yml

commit 2b44fe40f720bece87cab820a0c7c3bc00597367
Author: jdohbeecanhealth 106199539+jdohbeecanhealth@users.noreply.github.com
Date: Tue May 31 13:48:40 2022 -0700

Create dotnet.yml

commit 48ea87214068b44c65bfcdb8bb02435a6f55dc46
Author: jdohbeecanhealth 106199539+jdohbeecanhealth@users.noreply.github.com
Date: Mon May 30 17:50:28 2022 -0700

Add or update the Azure App Service build and deployment workflow config

commit 9380e02b16dc200acb9d9ddafdeb43b7fc3cac45
Author: jdohbeecanhealth 106199539+jdohbeecanhealth@users.noreply.github.com
Date: Fri May 27 16:09:31 2022 -0700

Add or update the Azure App Service build and deployment workflow config

:…skipping…
commit cd53738ab34b71732e3d23bb51ac96620bcbbfd1 (HEAD → master)
Author: jdohbeecanhealth 106199539+jdohbeecanhealth@users.noreply.github.com
Date: Tue May 31 13:58:30 2022 -0700

test

commit e2bf9f46ae7fbdc0eaec143241b560a2f81300d2
Author: jdohbeecanhealth 106199539+jdohbeecanhealth@users.noreply.github.com
Date: Tue May 31 13:53:30 2022 -0700

Create azure-webapps-dotnet-core1.yml

commit 2b44fe40f720bece87cab820a0c7c3bc00597367
Author: jdohbeecanhealth 106199539+jdohbeecanhealth@users.noreply.github.com
Date: Tue May 31 13:48:40 2022 -0700

Create dotnet.yml

commit 48ea87214068b44c65bfcdb8bb02435a6f55dc46
Author: jdohbeecanhealth 106199539+jdohbeecanhealth@users.noreply.github.com
Date: Mon May 30 17:50:28 2022 -0700

Add or update the Azure App Service build and deployment workflow config

commit 9380e02b16dc200acb9d9ddafdeb43b7fc3cac45
Author: jdohbeecanhealth 106199539+jdohbeecanhealth@users.noreply.github.com
Date: Fri May 27 16:09:31 2022 -0700

Add or update the Azure App Service build and deployment workflow config

commit dab2089f3ff92a6b091f2a902de1b97395fa621e
Author: jdohbeecanhealth 106199539+jdohbeecanhealth@users.noreply.github.com
Date: Wed May 25 16:35:36 2022 -0700

Create azure-webapps-dotnet-core.yml

commit 3b648aef91429639cf2aa283746406e7b9e9f8d0
Author: Justin Doh JDoh@Beecanhealth.com
Date: Wed May 25 14:37:23 2022 -0700

Add project files.

commit 01e9b5c837c9a81cab7c0a6d86efb9b730ca0170
:

I’m not sure. I’m not familiar with the interface you’re using. I usually use the command line or git-cola. Hopefully someone will be along shortly to give you some further advice.